The code you provided has several major issues. If the lecture says to use gets()
, throw it into the trash, use fgets()
instead. The reason why, you can find in this link:
Why is the gets function so dangerous that it should not be used?
Apart from that, The lecture seems to not even provided you the knowledge to correctly pass parameters or to output values of variables correctly.
I recommend you to read a good C starting book, f.e. this. A list of recommended books can be also found here:
The Definitive C Book Guide and List
To only focus one issue, the output:
printf("There are %d digits in your string.");
This use of printf()
is incorrect. Where shall the value specified by %d
come from? The %d
format specifier is missing a corresponding argument which points to an integer value or an int
variable, like:
int a = 10;
printf("a = %d",a);
%d
requires a matching argument of type int
to actually print a value. Else the behavior is undefined.
This shall in all cases give a diagnostic. Never ignore compiler warnings.
Why should I always enable compiler warnings?