format '%s' expects argument of type 'char *'

后端 未结 7 539
野趣味
野趣味 2021-01-11 10:32
#include 
int main(void)
{
    int i,j,k;
    char st;
    printf(\"enter string\\n\");
    scanf(\"%s\", st);         


        
7条回答
  •  误落风尘
    2021-01-11 11:03

    Use char *st; or an array like char st[50];.

    When you complete the usage of a char pointer, you should deallocate the memory used by the pointer. This can be done using free(st); function.

    EDIT : As you are printing string and if you are using pointer, you can do:

    printf("the entered string is %s\n",st);
    printf("the entered string is %s\n",*st); // This will work in both cases, if you use char *st or char st[50]
    

提交回复
热议问题