mercredi 27 juillet 2016

I can´t print a string that was read using the "gets" function [duplicate]

This question already has an answer here:

It works if I read the string value first and then the int value. I tried use function gets instead of scanf because gets lets me read more than one word in the same line.

I also tried with fgets but it has the same problem.

I'm using cygwin 32 bit compiler version 2.874. I using codeblocks ide 13.12.

#include <stdio.h>
#include <stdlib.h>

int main() {
    int i;
    char s[10];

    printf("Value int:n");
    scanf("%d",&i);
    printf("%dn",i);

    printf("Value string:");
    fflush(stdin);
    gets(s);
    printf("%sn",s);

    getchar();
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire