-Wall
flag to show all warnings.
And, of course, where necessary, change your program so that it does not produce any warnings.someProgram.c
, let the name of the executable be
someProgram
, i.e. the same name, but without the .c at the end.
hello.c
that prints out
Hello World!
on a line.
output.c
.
It should contain the following declarations:
char c = 'a'; short s = 55; int n = 5; long int nn = 22l; /* that's ell, not one. Can also use = 22L */ long long int nnn = 33ll /* can also use = 33LL */ float x = 7.5f; double y = 99.1234567; long double z = 99.5L; char someString[] = "This is some string.";BUT DO NOT copy and paste. Type it in.
printf()
to produce exactly the following output:
c as an integer: 97 c as a character: a s is 55 n is 5 nn is 22 nnn is 33 x is 7.500 y is 99.12 z is 99.500000 someString is This is some string. "someString" is "This is some string."The last item output, like all the others, should end with a newline character.
printf()
function is invoked as printf(
format string, additional arguments)
.
In the printf()
statements, use the variable names for the additional arguments
, not the value of the variable. For example, use printf(" ... ", n)
,
not printf(" ... ", 55)
.
input.c
.
It should contain the following declarations:
int a, b, c; int scanfReturnValue;Write code to read in values for
a, b
and c
from standard
input and then print out the values read. First print out the value returned by
scanf in each case. The statement to read in the values and assign them to
a, b
and c
would look like this:
scanfReturnValue = scanf("%d %d %d", &a, &b, &c); printf("scanf returned %d\n", scanfReturnValue); printf("a = %d, b = %d, c = %d\n", a, b, c);Look at the
scanf()
statement. The "%d" says you're expecting to read in
an int (in decimal/base 10) and the "&" before the a, b
and c
indicates the address where a, b, c
are stored and scanf
reads
the input values entered and stores them at these addresses. (Remember that C, like
java, is pass by value.) Running your program might produce results like this:
$ $ input 45 33 22 scanf returned 3 a = 45, b = 33, c = 22 $ $The first 3 lines are echoed program input; the last 2 are program output.
$ input < fileNameWhat happens if there are ...
5 7 15.75
?5 7 hello
?5 7 99hello
?
char c = 'a'; short s = 55; int n = 5; float x = 7.5f; double y = 99.1234567; long double z = 99.5L; char someString[] = "This is some string.";Now, instead, you'll start with
char c; short s; int n; float x; double y; long double z; char someString[];