C Language Learning 007: redirecting standard inputs and outputs

Source: Internet
Author: User

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

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.