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?
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?
Only by the cross are you saved...
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?
Only by the cross are you saved...
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.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
just a basic question :
wat's the difference between char* and char?
Only by the cross are you saved...
for example, wat does this do:
char* newline = strchr(str, '\n');
if(newline)
{
*newline = '\0'; /* strip off trailing '\n' */
}
Only by the cross are you saved...
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.