Parsing File Input

The read_weather application is fine if all you want to do is print the contents of a file verbatim. However, if you'd like to do more with your stored data, you'll need a method of parsing the read lines into their respective parts.

This can be accomplished using the sscanf() function. This function, first introduced in Chapter 5, can break one string down into different pieces, using formatting parameters like those used with printf() and fprintf(). The basic syntax is

sscanf(string_to_parse, formatting,
					
					arguments…);

Obviously the number of arguments depends on how many elements are expected to be extracted from string_to_parse ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.