What I need to do is if
1)if the string "ab" doesn't contain a newline, I need to insert one back into the buffer.
2)If the file contains two consecutive blank lines, skip over it.
For the first half of the problem, I was thinking about checking 'line' for '\n'. However, how would I push '\n', so that the buffer of line would go from
'a' 'b' '\0' '\0'
to
'a' 'b' '\n' '\0'
Is there some kind of ANSI C function that would do this? Otherwise, I was thinking about maybe using some kind of stack.
For the second half of the problem, the only thing I could possibly think of would be to test if each line like
line[0]=='\n'
However, I have NO idea how to track if the previous line also had a blank line. Ideas?
hi frequency8,
i am not sure if i understand you problem totaly
add an \n when missing
ask your self when can this happen ? perhaps at the last line in file ?
Skip empty lines, i asume that empty means 'contains no char execpt \n'
why not compare this line with '\n' ?
to get extra points use gnu- getline() function. It saves you thinking about 'did i read the whole line or only part of it because my buffer is to small ?'
Regarding point 3. I have getline() on my Linux box. However, the target systems that I would be running this under use FreeBSD and OpenBSD. I'm not sure if getline() is available on these systems.
Okay, no before anyone starts to think "Hey, I might be doing this kids homework", I would like to point out that it's been over a decade since I've been in school. Anyhow, here is what I've attempted.