Why do I care?
readHelpers are a group of functions that I have written that will make
it easier to read input from the user. When you use scanf() and
gets(), sometimes you run into problems where a scanf will not stop and
wait for the user to type any input -- your program will ask the user
for the information, but then go straight on without giving the user a
chance to type anything. The methods needed to fix this are
painful to use, so I wrote the readHelpers to avoid the problem all
As we worked in lab on Friday, it became apparent that lots of you were
going to run into this type of problem with homework 3, hence these
What are they really?
There are three readHelper functions. Here are their prototypes:
readInt(void); // reads in a single
integer from the user, and then returns the number.
// reads in a single character from the user, and returns that
stringVar); // reads in an entire line from the
user, and fills in the passed in stringVar as a string (with a null
Here are some examples of how you might use these functions. Be
sure to read these carefully. Remember you don't have to use the
same variable names -- these are examples only!
Here is how you might use readInt():
printf("Type a number: ");
numVar = readInt();
And here is how you can use readChar():
printf("Type a character: ");
myChar = readChar();
printf("Type a string: ");
When do I use these?
Use these functions for homework 3 instead of scanf or gets. You
should not have any calls to scanf or gets in your code for homework
3. For homework 3, these calls will be in your main()
-- since main() will ask the user for the string to search and what
characters to look for in that string.
How do I use the files you gave us?
I've given you two files: readHelpers.h and
readHelpers.c. To use them, do the following:
- download both files into the same directory as your .c file for
- add the following to your source file, with your other includes:
"readHelpers.h" // note the double
quotes instead of the <>
- When compiling your code with gcc, you need to add readHelpers.c
to the end of your gcc line. If your program is called
homework3.c, your gcc would look like this:
# gcc -o homework3.exe homework3.c
That's all folks.....