Start by completing a small task that transforms the input data into a JSON-formatted output
1#include <stdio.h>2 3 intMain () {4 floatlatitude;5 floatlongtitude;6 Charinfo[ the];7 intStarted=0;8Puts"data[");9 while(SCANF ("%f,%f,%79[^\n]", &latitude,&longtitude,info) = =3){Ten if(started) { Oneprintf", \ n"); A } - Else{ -Started=1; the } -printf"{latitude:%f,longtitude:%f,info: '%s '}", latitude,longtitude,info); - } -Puts"\ n]"); + return 0; -}
Interestingly, we can directly produce a configured latitude and longitude file through the program directly generated JSON file, which is the data in the Gpsdata.csv file
42.123123,-71.321321, speed=41.123123,-71.421321, speed=11 43.123123,-71.621321, speed=44.123123,-71.321321, speed= - 45.123123,-71.321321, speed=42.523123,-70.321321, speed =
Run directly through the program, generate the Output.json file in the same directory as the program
Why is that?
When using scanf () to read data from the keyboard, and printf () to write data to the display, these two functions do not directly use the keyboard, the display, but instead use the standard input and standard output. When the program runs, the operating system creates standard inputs and outputs.
"<" operator redirection standard input
">" operator redirection standard output
C Language Learning 007: redirecting standard inputs and outputs