0
int main()

    int c,s;
    char h;
    printf("Enter the carbon\n");
    scanf("%d",&c);
    printf("Enter the hard\n");
    scanf("%c",&h);
    printf("Enter strength\n");
    scanf("%d",&s);
    
    printf("%d%d",c,s);
    printf("%c",h);
}

Output:

Enter the carbon

4

Enter the hard

Enter strength

My program is not reading character data types. Can anyone tell me the reason? The compiler is not showing any error.

  • Use scanf(" %c",&h); See the blank before the conversion specifier %c. – Vlad from Moscow Nov 08 '21 at 19:23
  • If you want to specifically read lines, use `fgets` rather than `scanf`, because the latter is not very suitable for guaranteeing newlines rather than other whitespace. Then, you would use `sscanf` on the buffer read by `fgets`. – Cheatah Nov 08 '21 at 19:37

0 Answers0