mardi 3 janvier 2017

Read strings in c in if instruction

i have a problem with read strings in c, when i add gets() function in if instruction, the program is stoping

Code:

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

int main()
{
    int n,i = 0;
    char sir[2000],ch;

    printf("Press you option: "); scanf("%d",&n);

    if(n == 1)
    {
        printf("text: "); gets(sir);

        printf("\nINPUT: ");
        for(i = 0;i < strlen(sir);i++)
            printf("%c",sir[i]);

    }
    return 0;
}

Any solution ?

Aucun commentaire:

Enregistrer un commentaire