End of Line character
I'm scanning in a line of words and need to stop at the end of a line from a data file.
push this is the first line
push this is the next line
push good luck
push this is the last assignment for the semester
the first word is what to do with the next set of data. Push words onto a stack, pop a certain number from stack....
HOw would I find the last word on a line?
Read the whole line until the character '\n' is found.
Read the whole line from the file and then test (if-else statement) for a ' ' char. Understand?
Looking for the last word on the line:
begin by searching for a space OR a newline, read everything.
if a newline is hit, this is the last word.
if a space is hit, set your index variable (usually i) to 0 and set the
string you used for reading to '\0', like string = '\0'
continue reading the line
the string you used should hold the last word of the line
by using getchar, you can easily read from input and only store the last word
else you'll have to use another index variable (j perhaps) and never set it to 0, unless the whole line is finished
for reading from file you'll need fgetc (of course)