#include <stdio.h> #include <stdlib.h> #include <string.h> //#if(1) int main() { FILE *fin,*fout; char str1[81],str2[81]; //假定每行不超過80個字符 char *infile = "in.c"; char *outfile = "out. char *p; fin = fopen(infile,"r"); // 讀格式打開,默認爲文本類型 fout = fopen(outfile,"w"); // 寫格式打開,默認爲文本類型 if((fin == NULL) || (fout == NULL)) { printf("打開文件失敗!\n"); exit(1); } // while(fscanf(fin,"%s",str1) == 1) while( fgets(str1,50,fin)) { // 在這兒處理串str1...... p=strstr(str1,"//"); if(p==NULL) strcpy(str2,str1); else { strncpy(p,"/*",2); strcat(str1,"*/"); strcpy(str2,str1);} fprintf(fout,"%s",str2); // 寫入文件 fprintf(fout,"\n"); } fclose(fin); fclose(fout); return 0; } //#endif #if(0) void main() { char a[10] = {0}; int i=0,N=10; while(fgets(a, N, stdin)) { fprintf(stdout, "%d %s@%d\n", i, a, strlen(a)); i++; } } #endif
註釋轉換
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.