Yes, I am retarded. 
Author Message
 Yes, I am retarded.

Hi.  I am relatively new to C, and so I am
constantly running in to little problems, most
of which I can fix myself.  However, this is not
one of them.  Here is the code to my short
program.  If you have been at C for more than a
month, you know what I am trying to do.

main()
{
        char name[81];
        int age;

        printf("What is your name? ");
        scanf("%s", name);
        printf("How old are you? ");
        scanf("%i", &age);
        system("cls");
        printf("Hello, %s.  You are %i years
old",name,age);

Quote:
}

This program runs fine, just so long as you only
have a first name.  If I were to enter the name
"Zippy Insomniac" the program would not give me
a chance to enter my age, and instead, say I am
120 years old.  Please help me out here, because
I need it.(Maybe mentally.)  Also, if you look
at this code and think "There is such a better
way to do that" then please, feel free to
rewrite it and send me the code.  Hopefully
documented, but not necesarily.  Thank you all
vary much.  I would prefer return mail at my
mailbox at:


Thanx,

Tyger



Tue, 26 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

use fgets() instead of the evil scanf() for the string input.

--
C-FAQ ftp sites: ftp://ftp.eskimo.com ftp://rtfm.mit.edu
Hypertext C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-FAQ Book: ISBN 0-201-84519-9.
Want Software?  Algorithms?  Pubs? http://www.infoseek.com



Wed, 27 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

The following was received in HTML.  If it does not appear as plain text, I'm
sorry.
Tyger, please do not use HTML when posting.  Your newsreader should have
an option for plain text.

What you need to do is get the FAQ for comp.lang.c.  The normal
depository for FAQs (and for that of comp.lang.c) is
ftp://rtfm.mit.edu/pub/usenet-by-group
(anonymous FTP will do).
You should treat it as required reading before posting.
Unfortunately, a scan of the FAQ will not directly answer this.
What you need to do is replace lines like
    scanf("%s",name);
with lines like
    fgets(name, sizeof name, stdin);
Because fgets will read the '\n' into the buffer,
using a char * you have already declared
(as in:
    char *p;
)
follow the fgets call with something like
    if ((p = strchr(name,'\n'))) *p = 0;

It is better if you do not ask for e-mail responses.
Some of us get quite exercised* about such
requests.
*exercise: to cause anxiety, alarm, or indignation


    Hi.  I am relatively new to C, and so I am constantly running in to little
problems, most of which I can fix myself.  However, this is not one of them.
Here is the code to my short program.  If you have been at C for more than a
month, you know what I am trying to do.
    main()

            char name[81];
            int age;

            printf("What is your name? ");
            scanf("%s", name);
            printf("How old are you? ");
            scanf("%i", &age);
            system("cls");
            printf("Hello, %s.  You are %i years old",name,age);
    }

    This program runs fine, just so long as you only have a first name.  If I
were to enter the name "Zippy Insomniac" the program would not give me a
chance to enter my age, and instead, say I am 120 years old.  Please help me
out here, because I need it.(Maybe mentally.)  Also, if you look at this code
and think "There is such a better way to do that" then please, feel free to
rewrite it and send me the code.  Hopefully documented, but not necesarily.
Thank you all vary much.  I would prefer return mail at my mailbox at:


                                                            Thanx,
                                                                Tyger



Wed, 27 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

To clear the screen, use clrscr( ).  To get the string, use gets( ). Scanf
sucks the big one.  Try %d instead of %i.



Wed, 27 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

BHamm2:

Quote:
>To clear the screen, use clrscr( ).

Gives me a syntax error.

Quote:
> To get the string, use gets( ).

Queen of the nasal demons.  Probably the only C  function in the world worse
than scanf().

Quote:
>Scanf
>sucks the big one.  

No argument there.

Quote:
>Try %d instead of %i.

Why?

--
C-FAQ ftp sites: ftp://ftp.eskimo.com ftp://rtfm.mit.edu
Hypertext C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-FAQ Book: ISBN 0-201-84519-9.
Want Software?  Algorithms?  Pubs? http://www.infoseek.com



Wed, 27 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

:To clear the screen, use clrscr( ).  To get the string, use gets( ). Scanf
:sucks the big one.  Try %d instead of %i.

Don't try using the non-standard clrscr() without checking your
implementation documentation.  If you do use it, don't expect
your code to be portable.

Don't use gets() unless you like input overwriting the operating
system or causing a segementation fault. Use fgets().

Scanf() is a poor poor choice, but there is nothing wrong
with %i unless you have decimal numbers with leading 0s.
It is more flexible than %d.



Wed, 27 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

Quote:

> To clear the screen, use clrscr( ).  

No. 'clrscr()' is not a standard function.

Quote:
> To get the string, use gets( ). Scanf sucks the big one.  

'scanf()' does indeed 'suck the big one,' but 'gets()' is much, much worse,
since it can never be used in a predictable and safe manner. Use 'fgets()'
instead.

Quote:
> Try %d instead of %i.

What difference do you expect that to make?

--
(initiator of the campaign for grumpiness where grumpiness is due in c.l.c)

Attempting to write in a hybrid which can be compiled by either a C compiler
or a C++ compiler produces a compromise language which combines the drawbacks
of both with the advantages of neither.



Wed, 27 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

Quote:


> > To clear the screen, use clrscr( ).

> No. 'clrscr()' is not a standard function.

> > To get the string, use gets( ). Scanf sucks the big one.

> 'scanf()' does indeed 'suck the big one,' but 'gets()' is much, much worse,
> since it can never be used in a predictable and safe manner. Use 'fgets()'
> instead.

Ok.  Please show me an example of using fgets().  write a line to get info into a
character array buf[].  Also, include any incidental header files I might need to
include.

                                                tyger



Wed, 27 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

Quote:


> > 'scanf()' does indeed 'suck the big one,' but 'gets()' is much, much worse,
> > since it can never be used in a predictable and safe manner. Use 'fgets()'
> > instead.

> Ok.  Please show me an example of using fgets().  write a line to get info
> into a character array buf[].  Also, include any incidental header files I
> might need to include.

        #include <stdio.h>

        int main(void)
        {
                char buf[80];

                fgets(buf, sizeof buf, stdin);
                printf("%s\n", buf);

                return(0);
        }

--
(initiator of the campaign for grumpiness where grumpiness is due in c.l.c)

Attempting to write in a hybrid which can be compiled by either a C compiler
or a C++ compiler produces a compromise language which combines the drawbacks
of both with the advantages of neither.



Wed, 27 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

Insulting yourself can be offensive to others if you use words like that.
It wont get you much help after you get through junior high.
   Try and be more respectful,
      Cheers,
         -Scott


Quote:

> --------------C8AA8C9C9E97057A906CB7DB
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit

> Hi.  I am relatively new to C, and so I am
> constantly running in to little problems, most
> of which I can fix myself.  However, this is not
> one of them.  Here is the code to my short
> program.  If you have been at C for more than a
> month, you know what I am trying to do.

> main()
> {
>         char name[81];
>         int age;

>         printf("What is your name? ");
>         scanf("%s", name);
>         printf("How old are you? ");
>         scanf("%i", &age);
>         system("cls");
>         printf("Hello, %s.  You are %i years
> old",name,age);
> }

> This program runs fine, just so long as you only
> have a first name.  If I were to enter the name
> "Zippy Insomniac" the program would not give me
> a chance to enter my age, and instead, say I am
> 120 years old.  Please help me out here, because
> I need it.(Maybe mentally.)  Also, if you look
> at this code and think "There is such a better
> way to do that" then please, feel free to
> rewrite it and send me the code.  Hopefully
> documented, but not necesarily.  Thank you all
> vary much.  I would prefer return mail at my
> mailbox at:


> Thanx,

> Tyger

> --------------C8AA8C9C9E97057A906CB7DB
> Content-Type: text/html; charset=us-ascii
> Content-Transfer-Encoding: 7bit

> <HTML>
> Hi.&nbsp; I am relatively new to C, and so I am constantly running in to
> little problems, most of which I can fix myself.&nbsp; However, this is
> not one of them.&nbsp; Here is the code to my short program.&nbsp; If you
> have been at C for more than a month, you know what I am trying to do.

> <P>main()
> <BR>{
> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char name[81];
> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int age;
> <BR>&nbsp;
> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("What is your name?
> ");
> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf("%s", name);
> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("How old are you?
> ");
> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scanf("%i", &amp;age);
> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; system("cls");
> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Hello, %s.&nbsp;
> You are %i years old",name,age);
> <BR>}
> <BR>&nbsp;

> <P>This program runs fine, just so long as you only have a first name.&nbsp;
> If I were to enter the name "Zippy Insomniac" the program would not give
> me a chance to enter my age, and instead, say I am 120 years old.&nbsp;
> Please help me out here, because I need it.(Maybe mentally.)&nbsp; Also,
> if you look at this code and think "There is such a better way to do that"
> then please, feel free to rewrite it and send me the code.&nbsp; Hopefully
> documented, but not necesarily.&nbsp; Thank you all vary much.&nbsp; I
> would prefer return mail at my mailbox at:
> <BR>&nbsp;

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Quote:
> Thanx,

<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

- Show quoted text -

Quote:
> Tyger</HTML>

> --------------C8AA8C9C9E97057A906CB7DB--



Wed, 27 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

Quote:

> Insulting yourself can be offensive to others if you use words like that.
> It wont get you much help after you get through junior high.

Thank you for your very informative and very helpful post. You have enlighted
and improved the lives of many people today. I'm sure the poster will be
entirely unable to thank you adequately. You might want to look a little
deeper than the subject line before blowing someone off entirely next time.

--
(initiator of the campaign against unwarranted rudeness in c.l.c)



Thu, 28 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

Quote:


> > Insulting yourself can be offensive to others if you use words like that.
> > It wont get you much help after you get through junior high.

> Thank you for your very informative and very helpful post. You have enlighted
> and improved the lives of many people today. I'm sure the poster will be
> entirely unable to thank you adequately. You might want to look a little
> deeper than the subject line before blowing someone off entirely next time.

> --
> (initiator of the campaign against unwarranted rudeness in c.l.c)

I concur.

 Scott:
  Retarded means slow and, your conotation besides, it may very
 well have been used correctly.  Perhaps Tyger is just a kid trying
 to learn how to program and has the melons to admit he doesn't
 understand something.  It usually takes the{*filter*}sure arrogant
 programmer many years to aquire this attitude and it doesn't help
 to have you slam his door with your stomach turning response.
 Just ignore the post if you're offended.  Do you ever wonder why
 programmers are considered antisocial?  Get in the game.

  Tyger:
   Where are you going to school hoss?  I'm curious to know
 because I thought students where started out with C++ nowadays
 and don't get hit w/ C, Pascal, and (dating myself) PL/1.
   In the old days (insert music here) you learned the basics and
 then took seven different languages that hammered home the
 same concepts over and over again.  You'd learn about arrays,
 procedures, functions, recursion, and file I/O with C, Pascal,
 Cobol, PL/1, fortran, RPG, and Assembler.  You had six
 languages under your belt before you even knew what a linked
 list was.
    I thought that nowadays they taught you C++ and then used it
 in the majority of their courses.  I always thought that this was
 a better way to approach the situation.  Get the kid in Data
 Structures in the Spring of the freshman year with C++ and then
 you have three years to APPLY the language, not just learn
 twenty before you get out.  After you get out of school you can
 learn as many languages as you like or need.  School should
 be for concepts.

 Anyway, let me know what the deal is...

  Lars



Thu, 28 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

Quote:
>   Tyger:
>    Where are you going to school hoss?  I'm curious to know
>  because I thought students where started out with C++ nowadays
>  and don't get hit w/ C, Pascal, and (dating myself) PL/1.
>    In the old days (insert music here) you learned the basics and
>  then took seven different languages that hammered home the
>  same concepts over and over again.  You'd learn about arrays,
>  procedures, functions, recursion, and file I/O with C, Pascal,
>  Cobol, PL/1, Fortran, RPG, and Assembler.  You had six
>  languages under your belt before you even knew what a linked
>  list was.
>     I thought that nowadays they taught you C++ and then used it
>  in the majority of their courses.  I always thought that this was
>  a better way to approach the situation.  Get the kid in Data
>  Structures in the Spring of the freshman year with C++ and then
>  you have three years to APPLY the language, not just learn
>  twenty before you get out.  After you get out of school you can
>  learn as many languages as you like or need.  School should
>  be for concepts.

>  Anyway, let me know what the deal is...

>   Lars

Well, I am not entirely sure how they go about things in colege, for I am still
stuck in highschool.  I have enjoyed programming computers since I was a little kid
on an Apple IIe, using basic.  Since then, I tried to do a little work in C++ on a
macintosh that my family owned, but now I have my own computer(early graduation
present) and it is an IBM compatible. So, I searched for new languages.  I found a
couple iterations of basic that were a far (and much nicer, by the way) cry from
what I ha learned, but it was more than close enough to get me restarted.  I then
began to look for info on C on my own, just forsaking the two plusses as an extra
layers of convenience(maybe?) that isn't absolutely nessecary.
    I asked this question because The books I have been trying to use to teach
myself use scanf almost exclusively(in the first half atleast.)  However, I now
know some of the evils and have resorted to using fgets() on stdin.
    And so, there is my life story.  Any advice to a new programmer would be much
obliged.  Thank you all for you time.  We now return you to your regularly
scheduled program.

                                        Tyger

        p.s.To scott, who responded to my subject header, not my query, incase you
read this.  I Do Not Like You.
        p.p.s. To everyone else:  Thank you for letting me vent.  :)



Thu, 28 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

Quote:

>     I asked this question because The books I have been trying to use to teach
> myself use scanf almost exclusively(in the first half atleast.)  However, I now
> know some of the evils and have resorted to using fgets() on stdin.

Well, actually, IMHO learning scanf() first is not necessarily a bad
thing. It's bad programming practice (later), but as an initial
pedagogical approach there is some justice to it.

fgets() is useful precisely because it's safe, but you are likely to use
sscanf() on the contents of the buffer filled by fgets() anyway.
Teaching scanf() before sscanf() makes a bit of sense, as it provides
the learner with the opportunity to *see* the operations of the function
(as they're typing it in) instead of it happening invisibly within a
buffer as with sscanf().

Just because scanf() is a bad function to *use* doesn't mean that it's
bad to learn - and learn well - at all.

I.
--
----------------------------------------------------

Toronto, Canada    http://www3.sympatico.ca/ian.hay/
- Spam and HTML mail are emphatically not welcome. -
----------------------------------------------------



Fri, 29 Sep 2000 03:00:00 GMT  
 Yes, I am retarded.

Or you could just flush STDIN after you get the name.  Not the prettiest and
not better then the previous suggestion, just faster.

Quote:

>The following was received in HTML.  If it does not appear as plain text,
I'm
>sorry.
>Tyger, please do not use HTML when posting.  Your newsreader should have
>an option for plain text.

>What you need to do is get the FAQ for comp.lang.c.  The normal
>depository for FAQs (and for that of comp.lang.c) is
>ftp://rtfm.mit.edu/pub/usenet-by-group
>(anonymous FTP will do).
>You should treat it as required reading before posting.
>Unfortunately, a scan of the FAQ will not directly answer this.
>What you need to do is replace lines like
>    scanf("%s",name);
>with lines like
>    fgets(name, sizeof name, stdin);
>Because fgets will read the '\n' into the buffer,
>using a char * you have already declared
>(as in:
>    char *p;
>)
>follow the fgets call with something like
>    if ((p = strchr(name,'\n'))) *p = 0;

>It is better if you do not ask for e-mail responses.
>Some of us get quite exercised* about such
>requests.
>*exercise: to cause anxiety, alarm, or indignation


>    Hi.  I am relatively new to C, and so I am constantly running in to
little
>problems, most of which I can fix myself.  However, this is not one of
them.
>Here is the code to my short program.  If you have been at C for more than
a
>month, you know what I am trying to do.
>    main()

>            char name[81];
>            int age;

>            printf("What is your name? ");
>            scanf("%s", name);
>            printf("How old are you? ");
>            scanf("%i", &age);
>            system("cls");
>            printf("Hello, %s.  You are %i years old",name,age);
>    }

>    This program runs fine, just so long as you only have a first name.  If
I
>were to enter the name "Zippy Insomniac" the program would not give me a
>chance to enter my age, and instead, say I am 120 years old.  Please help
me
>out here, because I need it.(Maybe mentally.)  Also, if you look at this
code
>and think "There is such a better way to do that" then please, feel free to
>rewrite it and send me the code.  Hopefully documented, but not necesarily.
>Thank you all vary much.  I would prefer return mail at my mailbox at:


>                                                            Thanx,
>                                                                Tyger



Fri, 29 Sep 2000 03:00:00 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. I am a retard (perhaps a simple problem??)

2. yes I am willing to

3. Undeclared Identifier - yes - I am ashamed

4. Ada better than C / C++ ? People say YES YES YES

5. a retarded question

6. C for the mentally retarded!

7. Bedeviled Retard Seeks Ingenious Angels

8. Help SQL server and MFC, I feel retarded!

9. I am new to programming and am lost

10. ThreadPool yes or no

11. Function Yes, Operator No

12. static functions--yes or no?

 

 
Powered by phpBB® Forum Software