When scanf("%c", &link[0]);
reads the next byte from stdin
, it gets the pending newline left by the previous call scanf("%s", link);
.
You should use scanf(" %c", &link[0]);
to first skip any white space and read the next character.
There are other problems in your code:
MAX_lIMIT
should probably be MAX_LIMIT
scanf("%s", link);
may overflow the destination array if more than 99 characters are typed without whitespace. Use scanf("%99s", link);
- always test the return value of
scanf()
- printf("%c", link[0]);` should probably also print a newline for the output to be visible to the user.
- printf("%c", link);
is incorrect, it should be
printf("%s\n", link);`
Here is a modified version:
#include <stdio.h>
#define MAX_LIMIT 100
int main() {
char link[MAX_LIMIT];
if (scanf("%99s", link) != 1)
return 1;
printf("%s, Write the new version of the script.\n", link);
printf("%c\n", link[0]);
if (scanf(" %c", &link[0]) != 1)
return 1;
printf("%s\n", link);
return 0;
}