【发布时间】:2020-08-29 22:30:19
【问题描述】:
我无法理解这段代码我已经留下了关于 strcopy 的评论行。你能给我解释一下吗?已经谢谢了。我是 c 的新手,正在努力提高自己。有时我卡在某个地方,在这种情况下我找不到任何解决方案。
#include <stdio.h>
#include <string.h>
#define SIZE 1000
int main(){
int lwd,cnt;
char read1[SIZE];
char true;
FILE *r = fopen("test.txt","r");
if(r==NULL){
printf("Er.");
}
FILE *cpy =fopen("temp","w");
if(cpy==NULL){
printf("Er.");
fclose(r);
}
printf("Please enter whic line you wanna remove:");
scanf("%d",&lwd);
while(!feof(r)){
strcpy(read1,"\0"); // what does it mean?
fgets(read1,SIZE,r);
if(!feof(r)){
cnt++;
if(cnt != lwd){
fprintf(cpy,"%s",read1);
}
}
}
fclose(r);
fclose(cpy);
remove("test.txt");
rename("temp","test.txt");
FILE *read;
read = fopen("test.txt","r");
if(read == NULL){
printf("Error.");
fclose(read);
}
true=fgetc(read);
while(true != EOF){
printf("%c",true);
true=fgetc(read);
}
getch();
return 0;
}
【问题讨论】:
标签: c