C Language Learning: Pipeline Connection input and output, language learning
Now, you need to filter the data in the gpsdata.csv file and output the data that meets the criteria to output. in a json file, the first method is to modify the previous code. But if we don't want to modify the original code, we can get the expected results. How can we achieve this?
42.0908,-71.2316, speed = 2137.1908,-74.2322, speed = 1942.0908,-71.3312, speed = 2044.5908,-70.2314, speed = 1739.0908,-62.2512, speed = 1943.0908,-60.1311, speed = 1645.0908,-65.2316, speed = 20
We need to use pipelines to connect the standard output of a process to the standard input of another process, and use the "|" symbol to represent it.
Now let's implement the code of conditional handsome selection. we name the program bermuda
1 # include <stdio. h> 2 3 int main () {4 float latitude; 5 float longpolling; 6 char info [80]; 7 while (scanf ("% f, % f, % 79 [^ \ n] ", & latitude, & longpolling, info) = 3) {8 if (latitude> 40) & (latitude <44 )) {// filter condition 9 printf ("% f, % f, % s \ n", latitude, longpolling, info); 10} 11} 12 return 0; 13}
Finally, we can see that the output. json file contains data that meets the conditions (latitude> 40) & (latitude <44 ).
The advantage of pipelines is that we can separate each small program to complete its own single task and decouple the program.