470,855 Members | 1,230 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

Re: An interesting c program for beginners

Niz
On 2008-05-05 12:23:26 +0100, ap******@gmail.com said:
>
printf("First name: ");
gets(first);
printf("Last Name: ");
gets(last);
printf("Age: ");
scanf("%d", age);
printf("Social security number (no hyphens, just 3 figures): ");
scanf("%d", ssn);
printf("Salary: ");
scanf("%f", salary);
Use fgets() instead of gets() it is much safer.

Jun 27 '08 #1
1 1397
Small nit:

"Niz" <ni*@nicetry.comwrote in message
news:2008050513182216807-niz@nicetrycom...
On 2008-05-05 12:23:26 +0100, ap******@gmail.com said:
> printf("Social security number (no hyphens, just 3 figures): ");
Three figures? All the SSN's I've seen are nine.

Did I miss something earlier in the thread where you wanted only three digit
portion of the SSN? If so, it seems the prompt should say so.

Also, I thought it wasn't guaranteed (assured? assumed?) that any output
would occur without a newline or an fflush. When I did stuff like this, I
used:

printf("Social security number (no hyphens, just 9 figures): ");
fflush(stdout);
scanf("%d", ssn);

In cases where I forgot the fflush, for some platforms it worked as desired
anyway. But on others, the prompts wouldn't appear until. In most of those
cases the prompt appeared after I hit Enter for the input value, like this:

123456789Social security number (no hyphens, just 9 figures
[]

That [] represents the cursor at the beginning of the next line.

But I also remember one system where NONE of the prompts appeared at all.
Then when I did a printf, which had a newline, all the prompts showed up at
the same time, followed by the printf text. The cause being how the
c-library and/or operating system did output buffering.

- Bill

Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by coolcsgeek | last post: by
27 posts views Thread by xeys_00 | last post: by
6 posts views Thread by robertnielsen | last post: by
26 posts views Thread by v4vijayakumar | last post: by
15 posts views Thread by ianweise | last post: by
14 posts views Thread by hall.jeff | last post: by
19 posts views Thread by yltkhuu | last post: by
6 posts views Thread by tmallen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.