Accentuation in printing and blank fields

Asked

Viewed 47 times

0

Good people, I am just about to explore the world of Velopers, so I will need a discount for the many mistakes in my little program. I didn’t find an answer here, so I’ll ask.

The program below should simply register 5 people and print on the screen when requested. But although the program is accentuating in the menus, when printing on the screen the data registered they do not appear.

Another thing would be to not let the user "skip" parts of the registration, ie necessarily before continuing the registration the person should write something, even if it is a letter. Something like a loop, but for random characters..

#include <string.h>
#include <stdlib.h>
#include <locale.h>
#include <conio.h>
#include <ctype.h>
#include <time.h>

struct cad{
int codigo;
char nome[50];
char email[50];
char telefone[20];
};

int main(){
    srand(time(NULL));
    setlocale(LC_ALL,"");
    struct cad ficha [5];
    int vetor [5];
    int cod=1, op, i, j, info=0;
    char novo;
    do{
        printf("\n****  Base cadastral  ****\n");
        printf(" Selecione uma opção do Menu: \n\n");
        printf(" 1 - Insira um novo cadastro    \n");
        printf(" 2 - Mostrar todos os cadastros \n");
        printf(" 0 - Sair                       \n");
        printf("\nDigite a opção desejada: ");
        scanf("%d",&op);
        fflush(stdin);
        system("cls");
        switch (op){
            case 0: 
                printf (" Finalizando programa\n");
                break;
                
            case 1:
                do{
                    if( info > 4 ){
                        printf("\n\nLista cheia\n\n");
                        system("pause");
                        system("cls");
                        break;
                    }
                
                for (i=0; i<5; i++){
                vetor [i] = rand()%5;
                    for (j=0; j<i; j++){
                        if (vetor [i] == vetor [j]);
                        vetor[i] = (rand()%5);
                    }
                } 
                ficha[info].codigo = cod;            
                printf ("\nNovo Cadastro\n");
                printf (" Número de cadastro %d", cod); 
                
                printf("\n Insira nome:\n ");
                gets(ficha[info].nome);
                fflush(stdin);
                                
                printf ("\n insira email\n ");
                gets (ficha[info].email);
                fflush(stdin);
                    
                printf ("\n insira telefone\n ");
                gets (ficha[info].telefone);
                fflush(stdin);
                
                printf (" Pessoa cadastrada com sucesso!\n\n");
                printf (" -----------------------------------\n");
                system("\npause");
                system("cls");
                
                cod = cod + 1;              
                info = info + 1;
                
                printf("\n Cadastrar outra pessoa? S/N ");
                novo = getch();
                system("cls");                          
                }while(toupper(novo) != 'N' ); 
                break;
                
            case 2:
                if(info==0){
                printf("\n Sem cadastros \n");
                system("\npause");
                system("cls");
                }
                else
                    for (i=0;i<info;i++){
                    printf (" Código %d\n",ficha[i].codigo);
                    printf (" Nome %s\n",ficha[i].nome);
                    printf (" Email %s\n",ficha[i].email);
                    printf (" Telefone %s\n",ficha[i].telefone);
                    printf ("\n");
                    }
                printf("\n\n" );
                system ("pause");
                system("cls");
                break;
                
            default:
                printf("Opção inválida!\n");
                system("pause");
                system("cls");
            }
    }while(op != 0);
return 0;
} 
  • I believe that here: if (vetor [i] == vetor [j]); should not have this ; end because you are executing a null command in your loop and, I believe, what you want is to draw a new number. I don’t know if what you want is to avoid duplicates but if this is your logic you might not avoid.

  • opa, vlw by the feedback. I’ll fix this part.

  • Good morning Mr An idea is to check the size of the string for this I recommend using the [strlen();] (https://www.programiz.com/c-programming/library-function/string.h/strlen) in the case making the validation with x character.

No answers

Browser other questions tagged

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