I'm trying to output a bunch of variables to a file, with 2 numbers and a carriage return on each line.
I have two global int arrays declared all with variables in them.
void FileOutput()
{
FILE *f = fopen ("myfile.txt", "wb");
if (f == NULL) die("Couldn't open myfile.txt for writing, sorry");
else {
int x;
char temp_string[20];
for (x = 0; x <= 4; x++)
{
sprintf(temp_string, "%i %i \n", x_pos[x], y_pos[x]);
//printf("%i %i", x_pos[0], y_pos[0]);
printf("Calm down sir, PLEASE\n");
fputs (temp_string, f);
}
fclose(f);
}
printf("Don't worry sir, I'm from the internet\n");
}
Now, it puts it in the file fine, however, it all comes out as one line. The output on the screen comes out fine and I get carriage returns as expected there, however. I'd like it to come out this like this:
82 103
49 134
953 535
354 53
3535 234
The variables are purely aribtrary, this is an extension of a tutorial I'm following (I'm doing Wii homebrew development). I have to say, I've been doing programming for a while, and yet, I've never come across an issue quite like this that I haven't been able to resolve so easily.
Shoving \n everywhere does nothing (in regards to file output). I've tried injecting it when doing fputs() and also at the sprintf part, neither work. Honestly running out of ideas here. Anyone able to give me a hand figuring out what I'm doing wrong here?
Question
The Teej
Okay, it's 2am, and I'm at my wits end.
I'm trying to output a bunch of variables to a file, with 2 numbers and a carriage return on each line.
I have two global int arrays declared all with variables in them.
Now, it puts it in the file fine, however, it all comes out as one line. The output on the screen comes out fine and I get carriage returns as expected there, however. I'd like it to come out this like this:
82 103
49 134
953 535
354 53
3535 234
The variables are purely aribtrary, this is an extension of a tutorial I'm following (I'm doing Wii homebrew development). I have to say, I've been doing programming for a while, and yet, I've never come across an issue quite like this that I haven't been able to resolve so easily.
Shoving \n everywhere does nothing (in regards to file output). I've tried injecting it when doing fputs() and also at the sprintf part, neither work. Honestly running out of ideas here. Anyone able to give me a hand figuring out what I'm doing wrong here?
Major thanks in advance.
Link to comment
Share on other sites
14 answers to this question
Recommended Posts