Is EOF the same thing as NULL?
Printable View
Is EOF the same thing as NULL?
no, EOF is "end of file" and it's usually defined as -1 (while NULL is usually 0)
Well in something like-
what else can be used instead of EOF?Code:#include <iostream>
#include <string>
int main()
{
string c;
std::cout << "Type in your sentence: ";
while ((c = getchar()) != EOF)
std::cout << c;
return 0;
}
>what else can be used instead of EOF?
In this case anything, your code shouldn't compile. But assuming we changed it to something more reasonable:
You can replace EOF with any valid character returned by getchar. In this case a good test is for '\n' so that the loop stops after a single line.Code:#include <iostream>
#include <cstdio>
int main()
{
int c;
std::cout<<"Type in your sentence: ";
while ( ( c = getchar() ) != EOF )
std::cout<< char ( c );
}
-Prelude