- 论坛徽章:
- 780
|
回复 12# yyx_attach
C代码,输入文件in.txt 结果文件out.txt
Note: <aaa bbb>会变成<aaabbb>- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX_CHAR 1000
- int main(){
- FILE *fpin, *fpout;
- char lineSrc[MAX_CHAR+1];
- char lineDest[MAX_CHAR+1];
-
- if((fpin = fopen ("in.txt", "r")) == NULL){
- perror ("File in.txt open error!\n");
- exit(1);
- }
- if((fpout = fopen ("out.txt", "w")) == NULL){
- perror ("File out.txt open error!\n");
- exit(1);
- }
-
- while((fgets(lineSrc, MAX_CHAR, fpin)) != NULL){
- int i = 0;
- int j = 0;
- int flag = 0;
- memset(lineDest,0,MAX_CHAR+1);
- while(i<strlen(lineSrc)){
- char c = lineSrc[i];
- if(c=='<')
- flag = 1;
- else if(c=='>')
- flag = 0;
- if(flag==0||c!=' ')
- lineDest[j++] = lineSrc[i++];
- else
- i++;
- }
- fprintf(fpout,"%s",lineDest);
- }
-
- fclose(fpin);
- fclose(fpout);
- return 0;
- }
复制代码 |
|