Today I encountered an error when writing a file in a subdirectory of the C drive. I solved it after my own experiment. Make a small note.
The code is as follows:
#include
#include
#include
main()
{
int data[35];
int n=35, temp;
for(int i=0;i {
data[i]=i;
}
srand((unsigned)time(NULL));
FILE *fp;
fp=fopen( "C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\2016.11.22\random\Data Storage.txt","w");
for(int j=0;j {
temp=rand()%n;
printf("%4d",data[temp]);
fprintf(fp,"%4d",data[temp]);
if(temp+1!=n)
{
data[temp]=data[n-1];
}
n--;
}
fclose(fp);
}
At the beginning, just put the address of the file C:Program Files (x86)Microsoft Visual StudioMyProjects2016.11.22random copy to fprintf(), but an error will be reported when running. Finally, add one in front of each file to write the data.