O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required