C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-09-2003, 01:18 PM   #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
imbecile in C is offline   Reply With Quote
Old 07-09-2003, 01:49 PM   #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.
mart_man00 is offline   Reply With Quote
Old 07-09-2003, 01:55 PM   #3
End Of Line
 
Hammer's Avatar
 
Join Date: Apr 2002
Posts: 6,240
Re: display 10 consecutive lines...........

Quote:
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]
Hammer is offline   Reply With Quote
Old 07-09-2003, 02:10 PM   #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 !!
imbecile in C is offline   Reply With Quote
Old 07-09-2003, 02:15 PM   #5
End Of Line
 
Hammer's Avatar
 
Join Date: Apr 2002
Posts: 6,240
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]
Hammer is offline   Reply With Quote
Old 07-09-2003, 07:09 PM   #6
Rog
Registered User
 
Join Date: Jan 2003
Posts: 78
Quote:
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.











Rog is offline   Reply With Quote
Old 07-09-2003, 07:37 PM   #7
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,615
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.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?

Last edited by quzah; 07-09-2003 at 07:40 PM.
quzah is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 04:07 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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