1、在打开文件的同时删除文件的内容。
FILE* fp;
fp = fopen("c:\test12.txt","w");
if(fp==NULL)
return 0;
fclose(fp);
有时候需要包含
#include <io.h>
"w" Opens an empty file for writing. If the given file exists, its contents are destroyed.
#include<stdio.h>
#include<stdlib.h>
#define true 1
#define false 0
int main (int argc ,char *argv[])
{
int line;
char buffer[80];
FILE *fp = fopen(argv[1], "r");//读取文件
while(fgets(buffer, sizeof(buffer), fp)){//取一行.客官请多多注意fgets的特殊用法!
line++;
}
line--;
printf("There are %d lines in the file %s \n",line,argv[1]);
}