display 10 consecutive lines...........

This is a discussion on display 10 consecutive lines........... within the C Programming forums, part of the General Programming Boards category; Could anyone help me with this book exercise: "Display the user's name input from the keyboard in 10 consecutive lines, ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    display 10 consecutive lines...........

    Could anyone help me with this book exercise:

    "Display the user's name input from the keyboard in 10 consecutive lines, using the variable once..."

    I don't get it,..

    I have an idea that I'll type the name " John Lennon "
    and then it'll print the whole name down in 10 lines...

    please, give me your ideas... hints or perhaps
    a simple source code...

    thanks

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    913
    im not sure about the "variable once" part.

    can you do this?

    Code:
    #define MAX_NAME    25
    
    #include <stdio.h>
    
    int main() {
        int x = 1;
        char name[MAX_NAME + 1];
        
        printf("What is your name?\n");
        fgets(name, MAX_NAME, stdin);
        
        printf("\nHeres your name 10 more times\n");
        
        while(x < 11) {
            printf("%i) %s", x, name);
            
            ++x;
        }   
    
        return 0;
    }
    i used name once but the compiler could unroll the loop or you could say that the loop is using it 10 times. i dont like the problem.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: display 10 consecutive lines...........

    Originally posted by imbecile in C
    "Display the user's name input from the keyboard in 10 consecutive lines, using the variable once..."
    Sounds like another one of the strange questions, here's my effort for the day (note the use of the variable once):
    Code:
      char once[BUFSIZ];
      
      if (fgets(once, sizeof once, stdin))
      {
        /* Now loop to print 10 times */
      }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    Oi !! thanks !!

    I've taken full note of your ideas and hints...

    i'll compile it on our lab,.. and check everything !!

    Thanks a lot Dudes !!

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Just in case you didn't get it, mine was a sarcastic response
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Rog
    Rog is offline
    Registered User
    Join Date
    Jan 2003
    Posts
    78
    Originally posted by Hammer
    Just in case you didn't get it, mine was a sarcastic response
    Really? I thought you did exactly what the (very clearly worded) exercise stated.












  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    And even more amusing, we use the variable once once.
    Code:
    char once[BUFSIZ], *p = once;
    fgets( p, BUFSIZ, stdin );
    printf("%s%s%s%s%s%s%s%s%s%s"
           ,p,p,p,p,p,p,p,p,p,p);
    [edit] Variable renaming to make both fragments of the printf statement the same length. :P [/edit]

    Quzah.
    Last edited by quzah; 07-09-2003 at 07:40 PM.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem I Can't solve...
    By ferniture in forum C Programming
    Replies: 3
    Last Post: 07-15-2008, 02:51 AM
  2. Array help
    By Oklaskull in forum C Programming
    Replies: 19
    Last Post: 03-11-2008, 04:15 PM
  3. Continuous refresh
    By Bill83 in forum Windows Programming
    Replies: 11
    Last Post: 01-24-2006, 11:50 AM
  4. Heaps...
    By Nutshell in forum C Programming
    Replies: 14
    Last Post: 04-23-2002, 08:54 AM
  5. Formatting Output
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 03-26-2002, 12:33 AM

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