這是我的代碼。我需要創建10個文件,這種格式:C中的連接路徑和變量
0.txt
的1.txt
...
但我不能這樣做,結果是不同的。誰能幫忙?
#include <stdlib.h>
#include <string.h>
char* direccion(char *dirD,int number){
char buffer[100];
char *n;
char *q;
char* formato=".txt";
sprintf(buffer, "%i", number);
n= strcat(dirD,buffer);
q= strcat(n,formato);
return q;
}
int main(){
int u;
int number= 0;
int t= 0;
char* q = "e:/c9/";
for(t=0; t< 10 ; t++){
char* dir = direccion(q,number);
if(fopen(dir,"w")){
fopen(dir,"w");
u=1;
}
else{
u=0;
printf("Error\n");
}
number++;
}
return 0;
}
謝謝!
這是在Windows下嗎? – 2012-07-27 21:34:06
是的,僅在windows中。 – Sark 2012-07-27 21:39:51