NHA
asked on
Can I notufy the end of line in a file?
Hi
I have a problem in writing a c program that read from a file and search each line for a special character
the problem is I can not notify the end of line since I read a string each time and store it in an array then
I use a while loop within this array to search for special character ,the condition for this while loop is when I find a character != end of line ?
please I need a help so soon since my boss is expecting this to finish in 1 day?
I have a problem in writing a c program that read from a file and search each line for a special character
the problem is I can not notify the end of line since I read a string each time and store it in an array then
I use a while loop within this array to search for special character ,the condition for this while loop is when I find a character != end of line ?
please I need a help so soon since my boss is expecting this to finish in 1 day?
Are the lines in the file terminated with a carriage return or a line feed?
What does the file look like?
Are all of the lines the same length?
What does the program do?
What does the file look like?
Are all of the lines the same length?
What does the program do?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
fgets will read an entire line, so you know there is going to be a '\n' in buff[strlen(strlen)-1] or not at all (buff was too small.)
although it probably won't make a noticible difference except on larger files, I would remove the strlen call from the for loop. It is just good programming practice.
int len;
/* some code here */
len = strlen(buff);
for ( i = 0; i < len; i++ )
{
/* loop code */
}
int len;
/* some code here */
len = strlen(buff);
for ( i = 0; i < len; i++ )
{
/* loop code */
}
why doing a loop ? wouldn't be strtok function more appropriate ?
If the line needs to be unmodified (for whatever reason), strchr would be better, but I agree with Oliv. A loop really isn't needed.
This question was awarded, but never cleared due to the JSP-500 errors of that time. It was "stuck" against userID -1 versus the intended expert whom you awarded. This corrects that and the expert will now receive these points, all verified.
Moondancer
Moderator @ Experts Exchange
Moondancer
Moderator @ Experts Exchange
The newline character is '\n'
You could use the function fgets(), which can retrieve an entire line at once.