#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
using namespace std;
int main()
{
system("cls");
ofstream dat_in;
dat_in.open("zd4.txt");
dat_in << "";
char sentence[500] = "";
while (sentence[0] != '*' && strlen(sentence) != 1)
{
cout << "Input sentence: ";
cin.getline(sentence, 500);
if (sentence[1] != '*' && strlen(sentence) != 1)
dat_in << sentence<< "#";
}
}
(I'm not really good at C++ so please bear with me)
The while loop above should stop executing when the inputted sentence is simply "*" but it ends whenever the sentence is 1 character long. I've tried doing sentence!="*"
but it did not work and the loop would never end. What is the problem here? Is there an easier way of doing it?