simple c question (getline)
I have a line-oriented file-format, and use get line to retrieve the data. However, the (string) data can not have the newline character. I am trying to write a function that doesn't return a string with the newline, but I'm having trouble:
Code:
char * getlineNoEndl(FILE *file) |
Different operating systems use different End Of Line markers. An easy way would be to do something like this:
Code:
int i; |
I think the reason the original wasn't working is that the second argument to getline gets filled in with the amount of space *allocated* to the pointer in the first argument, not the actual number of characters read. You should be using the return value of getline to find the position of the newline instead.
I *believe* that fopen without the "b" modifier to the mode will convert whatever the system's newline character is to \n, so you don't have to worry about different newlines. I'm not sure if I'm remembering right though. |
Got it working with this:
Code:
char * getlineNoEndl(FILE *file) |
All times are GMT -5. The time now is 02:37 AM. |