Strange Print-outs

I have this program that won't print everything I tell it to. It's very strange.

In the middle of the program I wrote:
1
2
3
printf("MADE IT HERE!");
printf("Sat up LUID's.\n");
printf("MADE IT HERE!");


That is literally 3 lines of it in a row.
It prints the first "MADE IT HERE!" then prints "Sat up LUID's" so my output looks like:
MADE IT HERE!Sat up LUID's.
and then the code seems to completely go past the next "MADE IT HERE!" until it reaches the error I'm having.

Does anyone have any ideas about this?
Show all the code.
The whole program is really big. One file alone (out of like 30) is over 5000 lines of code.

But the rest of the code shouldn't have any bearing on why two of the printfs worked and the third didn't should it?

There is NO code in between the printfs I listed above.
Then show the error you get. That would be a help to us, also.
I just get a Segmentation fault sometime after "Sat up LUID's." but I don't know when.

That's why I'm trying to narrow it down in my code with the "MADE IT HERE!"s.

Edit: When I debug with gdb, I can step past the "Sat up LUID's." and the debugger will actually see the next line where I try to output "MADE IT HERE!". When I hit step, though, it just shows the next line after that without showing the output.
Last edited on
It's obviously that printfs work normal. An error is somewhere else. If you doubt about them try this:
1
2
3
puts("MADE IT HERE!");
puts("Sat up LUID\'s.\n");
puts("MADE IT HERE!");
Ok, changing 'printf' to 'puts' made the next "MADE IT HERE!" show up.

I still don't understand why that matters, though, if the first two worked?
output is buffered. Your data was probably being printed, it just wasn't being flushed. If it's not flushed, it won't be visible on screen.

Flushing occurs automatically on new lines. So...

1
2
3
4
5
printf("MADE IT HERE!");
printf("Sat up LUID's.\n"); // <- this newline would cause all output to be flushed

printf("MADE IT HERE!"); // <- whereas this would just sit in the buffer and not be visible
 // until flushed.  Since there's no newline 


puts might output and flush implicitly, whereas printf might not.

Possible solutions are to add a newline printf("MADE IT HERE!\n");

or explicitly flush: fflush(stdout); *

* Note I'm not sure if 'stdout' is the correct name for it. Maybe it's STDOUT? try it and see.
I switched it back to printf and added a newline to see if that worked and it did. Thanks for letting me know, that was really bothering me.
Topic archived. No new replies allowed.