Format '% s' erwartet Argument vom Typ 'char *'

#include <stdio.h>
int main(void)
{
    int i,j,k;
    char st;
    printf("enter string\n");
    scanf("%s", st);
    printf("the entered string is %s\n", st);
}

Das Kompilieren des obigen Programms gibt mir eine Warnung:

warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat]
palindrom.c:8:1: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat]

Was mache ich hier falsch?

Folgendes passiert, wenn ich es starte:

$ ./a.out
enter string
kiaaa
the entered string is (null)

Bearbeiten:

Hier ist eine andere Version des Codes (gemachtchar st; inchar *st):

#include <stdio.h>
int main(void)
{
    int i,j,k;
    char *st;
    printf("enter string\n");
    scanf("%s", st);
    printf("the entered string is %s\n", st);
}

Zur Laufzeit verhält es sich jedoch genauso.

Antworten auf die Frage(7)

Ihre Antwort auf die Frage