How do I create a loop which will go to each line and read each line in a text file? wat's the syntax like?
Printable View
How do I create a loop which will go to each line and read each line in a text file? wat's the syntax like?
also, i did find a tutorial in this site about File I/O but the tutorial was suited for C++ and not for C, anybody know of a good tutorial online for this purpose?
I didn't try searching Cprogramming.com, but I'm sure it's been asked and answered here. But this example did come to mind.
just a basic question :
wat's the difference between char* and char?
for example, wat does this do:
char* newline = strchr(str, '\n');
if(newline)
{
*newline = '\0'; /* strip off trailing '\n' */
}
strchr returns a pointer to somewhere inside of the string in question if the value is found. So if the string is "test\n"
will return a pointer to the '\n' in the string. Since it's a pointer, you can change what it points to and the string will change too. So *newline = '\0'; changes the '\n' to '\0' through the pointer.Code:char *newline = strchr(str, '\n');
Now, since strchr might not find the value it's looking for, you have to check for NULL, the value that is returned if no match is found. That's where the if statement comes in.