#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main()
{
FILE *fp;
char *path="e:\\ge";
char *name;
char *txt=".txt";
char *filepath;
int i=0;
name=(char*)malloc(3);
itoa(i,name,3);
filepath=(char *)malloc(strlen(path)+strlen(name)+strlen(txt)+1);
fp=(FILE *)malloc(100);
strcpy(filepath,path);
strcat(filepath,name);
strcat(filepath,txt);
printf("%s\n",filepath);
//*name=*name+1;
//printf("%c\n",*name);
while(1)
{
fp=fopen(filepath,"r");
if(!fp)
{
fp=fopen(filepath,"w");
break;
}
else
{
i++;
itoa(i,name,3);
printf("%c",*name);
free(filepath);
filepath=NULL;
filepath=(char *)malloc(strlen(path)+strlen(name)+strlen(txt)+1);
strcpy(filepath,path);
strcat(filepath,name);
strcat(filepath,txt);
printf("%s\n",filepath);
}
}
free(filepath);
}
写的可能比较繁琐
温馨提示:答案为网友推荐,仅供参考