如何用c语言删除一个特定位置text文档?

如题所述

stdio.h头文件中有个函数叫做remove可以完成这一功能

函数名: remove
功 能: 删除一个文件
用 法: int remove(char *filename);
程序例:
#include <stdio.h>
int main(void)
{
char file[80];
/* prompt for file name to delete */
printf("File to delete: ");
gets(file);
/* delete the file */
if (remove(file) == 0)
printf("Removed %s.\n",file);
else
perror("remove");
return 0;
}

以下是一个示范程序,假定要删除程序所在目录下一个叫做1.txt的文件

#include <stdio.h>

int main()
{
 if(remove("1.txt"))
 printf("Could not delete the file. \n");
 else printf("OK \n");
return 0;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-02-22

1、用remove函数
功 能: 删除一个文件  
用 法: int remove( const char *filename);
头文件:在Visual C++ 6.0中可以用stdio.h
返回值:如果删除成功,remove返回0,否则返回EOF(-1)。

2、例程(1.txt在程序目录下):

#include <stdio.h>
int main()
{
 if(remove("1.txt"))
 printf("Could not delete the file &s \n","1.txt");
 else printf("OK \n");
return 0;
}

相似回答
大家正在搜