Reading string by char till end of line C/C++
Reading string by char till end of line C/C++
You want to use single quotes:
if(c== )
Double quotes () are for strings, which are sequences of characters. Single quotes () are for individual characters.
However, the end-of-line is represented by the newline character, which is n.
Note that in both cases, the backslash is not part of the character, but just a way you represent special characters. Using backslashes you can represent various unprintable characters and also characters which would otherwise confuse the compiler.
The answer to your original question
How to read a string one char at the time, and stop when you reach end of line?
is, in C++, very simply, namely: use getline. The link shows a simple example:
#include <iostream>
#include <string>
int main () {
std::string name;
std::cout << Please, enter your full name: ;
std::getline (std::cin,name);
std::cout << Hello, << name << !n;
return 0;
}
Do you really want to do this in C? I wouldnt! The thing is, in C, you have to allocate the memory in which to place the characters you read in? How many characters? You dont know ahead of time. If you allocate too few characters, you will have to allocate a new buffer every time to realize you reading more characters than you made room for. If you over-allocate, you are wasting space.
C is a language for low-level programming. If you are new to programming and writing simple applications for reading files line-by-line, just use C++. It does all that memory allocation for you.
Your later questions regarding