Zach said:
I run Linux 2.6.18 and am seeking a way in C to get user input. I want
them to have the chance to enter a value and have it assigned to a
variable.
printf("Enter first integer: %d\n",s1);
scanf(&s1);
When I run this it automatically enters 0. It never pauses and thus
does not allow me to type in a value.
You start out by creating a pointer to an integer. You do not
set that pointer to any particular value, but you then try to
print out whatever random value it has, and you try to do so
using a format (%d) that tells printf that you are printing an
integer rather than the pointer-to-an-integer that you are passing.
After that you do nothing special before you try to read some
data. However, if you want your output to appear before the
read starts happening, you have to call fflush(stdout)
You then try to read some text data and have it parsed as
a number of some kind. However, in the place where you are
supposed to pass a format telling what kind of number to read,
you are passing a pointer to s1, so you are passing a pointer
to the (uninitialized) pointer to an integer . But you got *un*lucky
and scanf() did NOT just bomb and tell you something was wrong.
So s1 did not get read to, and whatever your program did after
that point continued to use whatever random value s1 had.
Your attempt has so many mistakes that it seems unlikely that you
have examined even a simple tutorial on reading data with C.
Rather than just giving you the code, I will give you advice:
Go and read a C tutorial
If I just gave you the code, you would be back with other things
you did not understand because you had not read up on fundamental
parts of C.