Skip to content

Commit

Permalink
61.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Lelouch-Lirong committed Mar 29, 2023
1 parent 807e132 commit 635124f
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
32 changes: 32 additions & 0 deletions C_Programming/61.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
源程序添加行号
*/
#include<cstdio>
#include<iostream>
using namespace std;

int main()
{
FILE *fp_r, *fp_w;
int no = 1;
char buf[1024];

fp_r = fopen("DATA5612.CPP", "r");
if(!fp_r){
cout<<"1:open the file fail"<<endl;
return 1;
}

fp_w = fopen("DATA5612.TXT", "w");
if(!fp_w){
cout<<"2:open the file fail"<<endl;
return 1;
}

while(fgets(buf, 1024, fp_r) != NULL){
fprintf(fp_w, "%04d %s", no++, buf);
}
fclose(fp_r);
fclose(fp_w);
return 0;
}
34 changes: 34 additions & 0 deletions C_Programming/DATA5612.CPP
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
源程序添加行号
*/
#include<cstdio>
#include<iostream>
using namespace std;

int main()
{
FILE *fp_r, *fp_w;
int no = 1;
char buf[1024];

fp_r = fopen("DATA5612.CPP", "r");
if(!fp_r){
cout<<"1:open the file fail"<<endl;
return 1;
}

fp_w = fopen("DATA5612.CPP", "w");
if(!fp_w){
cout<<"2:open the file fail"<<endl;
return 1;
}

while(fgets(buf, 1024, fp_r) != NULL){
cout<<no<<endl;
fprintf(fp_w, "%04d %s\n", no++, buf);
}
cout<<no<<endl;
fclose(fp_r);
fclose(fp_w);
return 0;
}
34 changes: 34 additions & 0 deletions C_Programming/DATA5612.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
0001 /*
0002 源程序添加行号
0003 */
0004 #include<cstdio>
0005 #include<iostream>
0006 using namespace std;
0007
0008 int main()
0009 {
0010 FILE *fp_r, *fp_w;
0011 int no = 1;
0012 char buf[1024];
0013
0014 fp_r = fopen("DATA5612.CPP", "r");
0015 if(!fp_r){
0016 cout<<"1:open the file fail"<<endl;
0017 return 1;
0018 }
0019
0020 fp_w = fopen("DATA5612.CPP", "w");
0021 if(!fp_w){
0022 cout<<"2:open the file fail"<<endl;
0023 return 1;
0024 }
0025
0026 while(fgets(buf, 1024, fp_r) != NULL){
0027 cout<<no<<endl;
0028 fprintf(fp_w, "%04d %s\n", no++, buf);
0029 }
0030 cout<<no<<endl;
0031 fclose(fp_r);
0032 fclose(fp_w);
0033 return 0;
0034 }
Binary file modified C_Programming/a.out
Binary file not shown.

0 comments on commit 635124f

Please sign in to comment.