- The source code file (test.c) copied below has my c code and console output commented out.
- I am trying to figure out why "Hello" is not printing to console output.
- I believe it may have something to do with
scanf([^\n])
reading in a'\n'
from previous line (see lines 14 & 15).
#include <stdio.h>
#include <string.h>
#define MAX_LEN 16
int main(){
char ch;
char s[MAX_LEN];
char sen[MAX_LEN];
scanf("%c", &ch);
scanf("%s", s);
scanf("\n");
scanf(" %[^\n]", sen);
scanf("%*c");
printf("%c\n", ch);
printf("%s\n", s);
printf("%s\n", sen);
printf("sen[15] = %c\n", sen[15]);
printf("string length = %lu\n", strlen(sen));
return 0;
}
Output
user@MacBook-18 c_the_hard_way % ./test
C
Hello
My name is Mikey
C
My name is Mikey
sen[15] = y
string length = 16