Write files to any directory in C + +

Source: Internet
Author: User
Today, encountered in the C-disk subdirectory of the error in writing files, the most of their own experiments to solve. A little bit of a record.

The code is as follows:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

Main ()
{
int data[35];
int n=35,temp;
for (int i=0;i<35;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 store. txt", "w");
for (int j=0;j<35;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 file's address C:\Program files (x86) \microsoft Visual Studio\myprojects\2016.11.22\random Copy to fprintf (), But in the run time will be error, and finally in each in, the file before adding a \ can write the data in.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.