Hi everyone
I'm going to write a program that takes string until end of file(eof). An condition must be considered and that is it must also terminate by a new line. For example when it's prompting me to enter a string if I press enter it must terminate and exit the program. How is it possible?
I tried saving carriage return("\t\n") as a string then I compared it with the entered string but it didn't work.
Any idea will be appreciated!
Hello, carriage return is \r (and \r\n is a windows new line with carriage return)
Try escaping the string to compare, use \\r\\n) it means \r\n as a string and not as a arriage return
I guess your idea works for me but I didn't get it correctly. Do you mean I have to compare the input string to \\r\\n? Here is piece of my code:
while(getline(cin, seq, '\n'))
{
if(seq=="\\r\\n")
return 0;
it doesn't work.
By the way I'm having a new problem!! I get out of range error for this part:
void Is_Same(unsigned long x, unsigned long y, unsigned long index)
{
char prev=seq[x];
x++;
while(x<=y)
{
if(prev=!seq[x])
{
Same[index]=false;
break;
}
prev=seq[x];
x++;
}
}
the seq is the input string containing 0's and 1's. It can be up to 1,000,000 long. x and y are ranges. I should compare digits in this range. If all of them are the same I output Yes.