用getc 和putc 复制一个程序代码到另一个文本中时怎么去掉//后面的部分
题目要求只复制代码,但要去掉 //后面的部分,这是题目:Write a program that reads a file containing a C program and outputs the program
to another file with all the // comments removed.
这是我写的,但不知道要怎么跳过//后面到另一行
#include <stdio.h>
int main (){
char c;
FILE *in= fopen ("a.txt","r");
FILE *out =fopen ("b.txt","w");
while ((c=getc(in)) !=EOF )
if (c== '/') "\n";
putc(c,out);
fclose(in); fclose(out); }
比如复制
aaaaa //bbbbb
ccccc
到另一个txt文本里,只保留
aaaaa
ccccc
[此贴子已经被作者于2019-10-9 21:13编辑过]