Hi everyone,
I need to write a bunch of x,y coordinates to a txt file one below the other using C(only).
I'm able to do so but all the coordinate values occur one next to the other.

Here's my code:

FILE *file1 = fopen ( "/cygdrive/d/newfile1.txt", "w" );
printf("The new coordinates are:\n");
    for(i=0;i<35;i++)
    {
    printf(" %f \t%f\n",x[i]*multFact,y[i]*multFact);
    fprintf(file1,"%f \t%f\n",x[i]*multFact,y[i]*multFact);
    }
fclose(file1);

P.S: I'm using netbeans6.9.1 and cygwin compiler.

"%f \t%f\n" says print a space, the first value, a space, then a tab, then the second value, then a newline.

You need to put a newline in between the first and second rather than a tab.

"%f \t%f\n" says print a space, the first value, a space, then a tab, then the second value, then a newline.

You need to put a newline in between the first and second rather than a tab.

I need the first x,y value in first line and the next set of x,y values in next line with a space(tab) between them.
The '\n' that I have given is getting printed as a small rectangular box in the o\p text file rather than making the next pair to go to the new line.

The o\p should be something like this;
1 3
2 6
and so on.

Sorry, I thought you meant
x1
y1
x2
y2

What are the data types of all of the variables?

Sorry, I thought you meant
x1
y1
x2
y2

What are the data types of all of the variables?

Its float.
And I found this interesting thing about it. When I copy paste the output from the text file to MS word etc then the values are one below the other.

Did u tried using "wt" or "wb" for opening the file?

Did u tried using "wt" or "wb" for opening the file?

Dude Thanks a million. "wt" works!!

FILE *file1 = fopen ( "/cygdrive/d/newfile1.txt", "wt" );

Most Welcome :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.