gets Não consegue guardar string "sim" mas consegue "ola"

alphaPi

Membro
Boas, estou a fazer um programa para a escola e deparei me com este problema:
A funcao 'gets' consegue guardar a string "ola" mas nao a string "sim" nem a string "nao"

isto na minha cabeca nao faz sentido pois afinal uma string é um conjunto de bits mas, gostaria de saber o porque de isto acontecer

O compilador que estou a usar é o do DEV C++, e o codigo onde estou a ter problemas está abaixo

Código:
serverAdd()
{   
    //Pointer declaration
    FILE *fp;
   
    //Variable Declaration
    int op,i;
   
    //Structures
    struct serverInfo
    {
        char serverName[64],clientName[100],clientEmail[100],serverQueryPassword[8],autoStart[8];
        int slots,port,serverID;
    }xx;
    //Structure creating 100 more 'serverinfo' Structures
    struct serverInfo serverInfoStruct[100];
   
    //File Opening to Append
    fp=fopen("servers.dat","a+b");
   
    //Asks how many servers user wants to insert into DB
    puts("Quantos Servidores quer introduzir? ");
    //Saves answer
    scanf("%d",&op);
   
    //For Cycle to ask user all necessary server info for DB
    for(i=0;i<=op-1;i++)
        {   
            printf("Insira O Nome do Servidor %d (MAX: 64 Caracteres) ",i+1);
            fflush(stdin);
            gets(serverInfoStruct[i].serverName);
           
            printf("Insira as Slots do Servidor %d (MAX: 512 Slots) ",i+1);
            fflush(stdin);
            scanf("%d", &serverInfoStruct[i].slots);
           
            printf("Insira a Porta do Servidor %d ",i+1);
            fflush(stdin);
            scanf("%d", &serverInfoStruct[i].port);
           
            printf("Auto Start?? no Server %d (MAX: 3 Caracteres (SIM/NAO)) ",i+1);
            fflush(stdin);
            gets(serverInfoStruct[i].autoStart);
           
            printf("Insira o UID do Servidor %d ",i+1);
            fflush(stdin);
            scanf("%d", &serverInfoStruct[i].serverID);
           
            printf("Insira a Password de ServerQuery do Server %d: (MAX: 8 Caracteres) ",i+1);
            fflush(stdin);
            gets(serverInfoStruct[i].serverQueryPassword);
           
            printf("Insira o Nome do Cliente do Server %d: (MAX: 100 Caracteres) ",i+1);
            fflush(stdin);
            gets(serverInfoStruct[i].clientName);
           
            printf("Insira o Email do Cliente do Server %d: (MAX: 100 Caracteres) ",i+1);
            fflush(stdin);
            gets(serverInfoStruct[i].clientEmail);
        }
   
    //Writes all the information above to 'fp'== servers.dat   
    fwrite(serverInfoStruct,sizeof(xx),op,fp);
   
    //File Closure
    fclose(fp);
}

serverInfoShow()
{
    //Pointer declaration
    FILE *fp;
   
    //Variable Declaration
    int svNumber,regs;
   
    //Structures
    struct serverInfo
    {
        char serverName[64],clientName[100],clientEmail[100],serverQueryPassword[8],autoStart[8];
        int slots,port,serverID;
    }xx;
    //Structure creating 100 more 'serverinfo' Structures
    struct serverInfo serverInfoStruct[100];
   
    //File Opening to Read Only
    fp=fopen("servers.dat","r+b");
   
    //Read File and Positioning on EOF (default positioning)
    svNumber=fread(serverInfoStruct,sizeof(xx),100,fp);
   
    printf("Existem %d Servidores\n",svNumber);
   
    puts("Qual e o servidor que pretende visualizar? ");
    scanf("%d",&regs);
   
    //Changing Positioning of file (SEEK_SET==BOF)
    fseek(fp,(long)(regs-1)*sizeof(xx),SEEK_SET);
   
    //Starts Reading from BOF
    fread(serverInfoStruct,sizeof(xx),100,fp);

        puts("\t ________________________");
        puts("\t|                        |");
        puts("\t| Informação do Servidor |");
        puts("\t|________________________|\n");
       
        printf ("O Nome do Servidor Nº %d é: %s\n",regs, serverInfoStruct[regs-1].serverName);
        printf ("A Quantidade de Slots do Servidor Nº %d é: %d\n",regs, serverInfoStruct[regs-1].slots);
        printf ("A Porta do Servidor Nº %d é: %d\n",regs, serverInfoStruct[regs-1].port);
        printf ("O Servidor %d tem AutoStart Ligado: %s\n",regs, serverInfoStruct[regs-1].autoStart);
        printf ("O UID do Servidor %d é: %d \n",regs, serverInfoStruct[regs-1].serverID);
        printf ("A Password de ServerQuery do Server %d é: %s\n",regs, serverInfoStruct[regs-1].serverQueryPassword);
        puts("_____________________________________________________________________________________________\n");
        puts("\t _______________________");
        puts("\t|                       |");
        puts("\t| Informação do Cliente |");
        puts("\t|_______________________|\n");
       
        printf ("O Nome do Cliente do Servidor %d é: %s\n",regs, serverInfoStruct[regs-1].clientName);
        printf ("O email do Cliente do Servidor %d é: %s\n",regs, serverInfoStruct[regs-1].clientEmail);
        puts("_____________________________________________________________________________________________");       
   
    //File Closure
    fclose(fp);
}
 
Back
Topo