This Blog is dedicated to Sir Johnson Lin
Learn flow chart from C language , master C with the chart!

flow chart and cpp source code to convert DOS/UNIX txt to unix_mac_dos format






D:\CPPcode\CnvrtDUM\CnvrtDUM.c++
 1 //++++++++++++++++++++++++++
 2  //      CnvrtDUM.cpp
 3  //++++++++++++++++++++++++++
 4  
 5  ///#include header
 6  #include <iostream>
 7  #include <fstream>
 8  #include <stdio.h> // C
 9  
10  
11  ///Using
12  using namespace std;
13  
14  
15  ///main_in
16  main(int argc,char *argv[])
17  {
18      
19      
20      ///declare
21      ifstream i_file;//ifstream i_file(argv[1]);//declare then open
22      ofstream ou_file, od_file,om_file;
23      string sMytext;
24      char xFileunix[30];
25      char xFiledos[30];
26      char xFilemac[30];
27      
28      
29      ///Open i_file
30      i_file.open(argv[1]);
31      
32      
33      
34      ///i_file?
35      if ( i_file==NULL)
36      {
37          cout << "Cannot open " << argv[1] << endl;
38          return(1);
39      }//end if
40      
41      
42      ///Prepare file name
43      sprintf(xFileunix,"%s%s", argv[1],"u");
44      sprintf(xFiledos,"%s%s", argv[1],"d");
45      sprintf(xFilemac,"%s%s", argv[1],"m");
46      
47      
48      ///Open o_file
49      //std::ofstream o_file( argv[2], std::ios_base::binary | std::ios_base::out );//declare then open
50      ou_file.open( xFileunix, std::ios_base::binary | std::ios_base::out );
51      od_file.open(xFiledos);
52      om_file.open(xFilemac);
53      
54      
55      ///Read at next blc
56      ///Loop to last line
57      while(getline (i_file, sMytext))
58      {
59          
60          
61          ///Write line+ NL
62          ou_file << sMytext<< "\n";
63          od_file << sMytext<< "\n";
64          om_file << sMytext<< "\r";
65          
66          
67          ///Display
68          cout << sMytext<< endl;
69          
70          
71          ///+
72      }//end while
73      
74      
75      ///Close files
76      i_file.close();
77      ou_file.close();
78      od_file.close();
79      om_file.close();
80      
81      
82      ///main_end
83      return 0;
84  } //main_end
85  
86  

沒有留言:

張貼留言