当我的程序在 main 中返回 0 时,程序退出,但控制不会返回到命令行。我什至尝试过exit(),但无济于事。有什么建议么
int main (int argc, char* argv[])
{
char name[100];
char reg[200];
char replace[200];
if(argc==3){
strcpy(reg, ".*");
strcat(reg, argv[1]);
strcat(reg, ".*");
}
else if(argc==4){
strcpy(reg, "\\(\\(.*");
strcat(reg, argv[3]);
strcat(reg, ".*");
strcat(reg, argv[1]);
strcat(reg, ".*\\)\\|\\(.*");
strcat(reg, argv[1]);
strcat(reg, ".*");
strcat(reg, argv[3]);
strcat(reg, ".*\\)\\)");
printf("\n%s\n", reg);
// exit(1);
}
printf("\n%s\n", reg);
strcpy(name, argv[1]);
strcpy(replace, argv[2]);
printf("\n%s\n", name);
// puts(realpath("./b/test2",NULL));
int reti;
char msgbuf[100];
regex_t regex;
/* Compile regular expression */
reti = regcomp(®ex, reg, 0);
if( reti ){ fprintf(stderr, "Could not compile regex\n"); exit(1); }
list_dir (".", regex, name, replace);
char line[BUFSIZ];
FILE *fp2=fopen("source.dat","r");
if(fp2==NULL)
printf("Problm opening: source.dat");
FILE *fp3=fopen("result.dat", "r");
if(fp3==NULL)
printf("Problm opening: result.dat");
char line2[1000];
int len;
while( (fgets(line2, BUFSIZ, fp2) != NULL) && (fgets(line, BUFSIZ, fp3) != NULL)) {
len=strlen(line);
if( line[len-1] == '\n' )
line[len-1] = '\0';
len=strlen(line2);
if( line2[len-1] == '\n' )
line2[len-1] = '\0';
rename(line, line2);
}
close(fp2);
free(fp2);
close(fp3);
free(fp3);
remove("source.dat");
remove("result.dat");
regfree(®ex);
return 0;
}
我的程序按照我的意图执行,但是当它完成 while 循环并释放所有内容时,控制不会在不按 ctr-C 的情况下返回命令行。还是不知道为什么。