El formato '% s' espera un argumento de 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);
}
La compilación del programa anterior me da una advertencia:
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]
¿Qué estoy haciendo mal aquí?
Esto es lo que pasa cuando lo ejecuto:
$ ./a.out
enter string
kiaaa
the entered string is (null)
Editar:
Aquí hay otra versión del código (hechochar st;
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);
}
Sin embargo, se comporta igual en tiempo de ejecución.