我正在尝试从当前工作目录中删除文件。当我尝试打印"无效的文件"当找不到文件时,它会抛出一个分段错误。这个片段是更大程序的一部分。
代码:
printf("\nEnter your current password:\t");
scanf("%s",temp2);
comp2 = strcmp(password,temp2);
file = (char*)malloc(100 * sizeof(char));
if(comp2 == 0)
{
int value;
printf("\nEnter the file name:\t");
scanf("%s",file);
sprintf(cmd,"rm -i %s",file);
value=system(cmd);
if(value == -1)
printf("\nFile not Found. Exiting Program");
}
else
printf("\nThe password is incorrect. Please try again.");
break;
请帮忙吗?提前谢谢。
答案 0 :(得分:1)
您可以使用删除功能
remove(file_name);
答案 1 :(得分:1)
使用删除(路径) - 它删除文件或目录。