Problem

This is a discussion on Problem within the C Programming forums, part of the General Programming Boards category; I am writing a program that among other things prints out an array of characters. In order for it to ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    4

    Problem

    I am writing a program that among other things prints out an array of characters. In order for it to work, I need to print a new line to the console. Without this, it freezes. Can anyone suggest why this is happening?

    Code:
    for(i = 5; i >= 0; i--){
            printf("%c", test[i]);
        }
        
    printf("\n");
    If I comment out the "printf("\n");" statement, it freezes before it gets to this part of the code. My program also makes use of threads. Any help would be much appreciated.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    On many systems, the console is line-buffered, that it the whole line isn't printed until you move to the next one, with "\n".

    EDIT: Mind you, printf outputs to "stdout" which is the standard output stream, and is buffered. On the other hand "stderr", standard error stream, isn't buffered! Just so you know. You could use "fprintf(stderr, ...)".
    Last edited by GReaper; 03-06-2012 at 01:06 PM.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    Thank you very much, sorted.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sleep() function problem or logic problem?
    By FernandoBasso in forum C Programming
    Replies: 7
    Last Post: 11-16-2011, 05:50 PM
  2. Replies: 4
    Last Post: 10-16-2008, 08:30 PM
  3. Replies: 27
    Last Post: 10-11-2006, 05:27 AM
  4. Visual Studio Linker problem or my problem?
    By OOPboredom in forum C Programming
    Replies: 2
    Last Post: 04-13-2004, 01:32 AM
  5. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 09:14 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21