format '% s' oczekuje argumentu typu '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);
}
Kompilowanie powyższego programu daje mi ostrzeżenie:
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]
Co ja tu robię źle?
Tak się dzieje, gdy go uruchamiam:
$ ./a.out
enter string
kiaaa
the entered string is (null)
Edytować:
Oto kolejna wersja kodu (wykonanachar st;
wchar *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);
}
Jednak zachowuje się tak samo w czasie wykonywania.