Thread: displaying a array to output

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Do the test before you print the character.

  2. #2
    Registered User
    Join Date
    Feb 2008
    Posts
    77
    Still having a problem. Heres how I tried to change the code:

    Code:
            printf("%c", sequence[0]) ;
            for(x = 1; x<strlen(sequence) ; ++x) // print 60 letters per line.
                {                                        
                     if((x%60 == 0) && (x != 0))
                        {
                            printf("\n") ;
                        }
                     else 
                        {
                        printf("%c", sequence[x]) ;
                        }
                }
    I even tried starting a x=0 in the for loop with the same conditional for the if loop

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    And you added an else clause why? Now sequence[60], sequence[120], etc will never print.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    77
    Thank you tabstop for the help. Everything works fine. Sorry for the frustration. I must reiterate that I am barely a novice to programming.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Let's stop and think for a moment. Here's how the loop goes:
    If the index is no dividable by 60, so for index 0, print the current character.
    Loop.
    Same for index 1 though 59.
    Coming back on index 60. Print newline. Loop.
    Index 61, print character, loop.

    Do you see the problem?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Output an array in a textbox
    By Diablo02 in forum C# Programming
    Replies: 5
    Last Post: 10-18-2007, 03:56 AM
  2. Displaying my glut output in my own class window.
    By Queatrix in forum Windows Programming
    Replies: 0
    Last Post: 10-19-2005, 10:09 AM
  3. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM