formato '% s' espera argumento do tipo '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);
}
A compilação do programa acima me dá um aviso:
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]
O que eu estou fazendo errado aqui?
Isto é o que acontece quando eu corro:
$ ./a.out
enter string
kiaaa
the entered string is (null)
Editar:
Aqui está outra versão do código (feitachar st;
para dentrochar *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);
}
No entanto, ele se comporta da mesma maneira em tempo de execução.