473,408 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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 1539
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: coolcsgeek | last post by:
i took a c++ intro cs course a few years back and recently decided to major in cs after much switching back and forth between majors. it seems my school has replaced most of it's intro level cs...
27
by: xeys_00 | last post by:
I'm a manager where I work(one of the cogs in a food service company). The boss needed one of us to become the "tech guy", and part of that is writing small windows programs for the office. He...
6
by: Kyle | last post by:
Hello all! I'm looking into developing a biological program for modeling and sequencing DNA and other biological processes. The program's main focus would be to look for similarities and...
6
by: robertnielsen | last post by:
i am new to c++ and am practicing programs. i am trying to write a program that a user enters a sequence of numbers and the program will pick out the lowest and highest numbers in the bunch. i...
26
by: v4vijayakumar | last post by:
Happened to see my old (last millennium) c code. Almost forgot that I wrote it . It is interesting. :-) int sqrt(int no) { int t; no = t * t; return t; }
15
by: ianweise | last post by:
hello, before i post my code for this, is there anyone out there at this moment? no sense in posting if no one is out there to read and answer it =P
14
by: hall.jeff | last post by:
I wrote the following simple program to loop through our help files and fix some errors (in case you can't see the subtle RE search that's happening, we're replacing spaces in bookmarks with _'s) ...
19
by: yltkhuu | last post by:
1. How does having a widely adopted C++ standard help game programmers? 2. What are the advantages ans disadvantages of employing the "using" directive? 3. Why might you define a new name for an...
6
by: tmallen | last post by:
Here's the code: http://pastebin.com/m21dfcc19 What could be improved? The script feels clumsy, and I have no experience refactoring Python code. This will eventually be a GUI FTP client. I'm...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.