简体   繁体   中英

Problem with C language, I don't understand the error

I'm learning C but I don't understand why the error appears on line number 9 ---> scanf("%[^\n]s",&cadena); // i tried with "%s" but still doesnt work.

#include <stdio.h>

int main(void)
{
    char cadena[40];

    printf("Ingrese cadena: ");
    fflush(stdin);
    scanf("%[^\n]s",&cadena);
    printf("La cadena es %s \n", cadena);

    return (0);
}

Remove the ampersand on cadena in scanf

scanf("%[^\n]", cadena);

An array decays to a pointer so you were actually passing a pointer to a pointer in that case.

Also you can just write it like this

scanf("%s",cadena);

Depends on your end goal though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM