C Language Learning 007: redirection of standard input and output, language learning 007
First, complete a small task of converting the input data to the json format output.
1 #include <stdio.h>
2
3 int main(){
4 float latitude;
5 float longtitude;
6 char info[80];
7 int started=0;
8 puts("data[");
9 while(scanf("%f,%f,%79[^\n]",&latitude,&longtitude,info)==3){
10 if(started){
11 printf(",\n");
12 }
13 else{
14 started=1;
15 }
16 printf("{latitude:%f,longtitude:%f,info:'%s'}",latitude,longtitude,info);
17 }
18 puts("\n]");
19 return 0;
20 }
It is worth thinking that we can directly generate a jsonfile by using a configured upload file, which is the data in the gpsdata.csv file.
42.123123,-71.321321,speed=21
41.123123,-71.421321,speed=11
43.123123,-71.621321,speed=18
44.123123,-71.321321,speed=17
45.123123,-71.321321,speed=21
42.523123,-70.321321,speed=20
Directly run the program and generate the output. json file in the same directory of the program.
Why?
When scanf () is used to read data from the keyboard, and printf () is used to write data to the display, the two functions do not directly use the keyboard and display, but use standard input and standard output. When the program is running, the operating system creates standard input and output.
"<" Operator redirection standard input
">" Operator redirection standard output