CITS2002 Systems Programming  
prev
next CITS2002 CITS2002 schedule  

What did we just read from the file?

Our call to the fgets() function will have read in all characters on each line of the dictionary but, if we're interested in processing the characters as simple strings, we find that we've got "too much".

Each line read will actually have:
a a r d v a r k \n \0

The character '\n', the familiar newline character often used in print(), is silently added to text lines by our text editors.

In fact on Windows' machines, text files also include a carriage-return character before the newline character.

W i n d o w s \r \n \0

As we know, we can simply turn this into a more manageable string by replacing the newline or carriage-return character by the null-byte.

 


CITS2002 Systems Programming, Lecture 7, p6, 12th August 2024.