C Language Learning 007: redirection of standard input and output, language learning 007

Source: Internet
Author: User

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

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.