How to add "" to an input

Asked

Viewed 21 times

0

How do I add "" to an input? I tried to do it in many ways but the one I got closest to was this, but it does not return a word, it returns "(null)"

int main(void) {
        char p;
        char x = 34;

        printf("Palavra: ");
        scanf("%s\n", p);
        printf("%c%s%c\n", x, p, x);

        return 0;

}

1 answer

1

That line:

scanf("%s\n", p);

should be:

scanf("%s\n", &p);

But if you want to fit a word will not fit, only one character fits. To fit a word use array.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.