Screen Printing Problems (C Language)

Asked

Viewed 96 times

0

I’m doing a job where it’s requested:

The system to be built will need to meet the functional requirements below:

1 - Have your ID (RA-Name-Course) 2 - Have an option menu. 2.1 - Include the registration of works. 2.2 - List all books. 2.3 - List all magazines. 2.4- List works by box.

But my code is with a problem at the time of printing on the screen he "eats" the first letter and only she, for example, say I want to be printed on the screen "Portugal programming", simply the first letter is not printed and the rest is getting "ortugal programming" without P. This is occurring in all the first letters of each line. Here is my code:

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



void menu(){

    printf ("\n\n1 - Cadastrar\n");
    printf ("2 - Listar todos os livros.\n");
    printf ("3 - Listar todas as revistas.\n");
    printf ("4 - Listar as obras por caixa.\n");
    printf ("0 - Sair\n");
}

FILE* AbreArquivo(char modo, char caminho[100]){

    FILE *arquivo;
    switch(modo){

        case 'g':
            arquivo = fopen(caminho,"wt");
            break;
        case 'l':
            arquivo = fopen(caminho,"rt");
            break;
        case 'a':
            arquivo = fopen(caminho,"a");
            break;
    }

    if(arquivo==NULL){

        printf("Nao foi possivel abrir o arquivo");
        exit(0);

    }

    return arquivo;
}

void FecharArquivo(FILE *arquivo){

    fclose(arquivo);

}

void Cadastra(char titulo[70],char editora[70], char autor[70], int caixa, int ano, int ISBN){

    FILE *arquivo;
    arquivo = AbreArquivo('a', "mapa.txt");
    fprintf(arquivo, " \n %s  %s\n  %s\n  \n%d  \n%d  \n%d", titulo, autor, editora, caixa, ano, ISBN);

    FecharArquivo(arquivo);
}

void CadastraRevista(char titulo[70],char editora[70], char autor[70], int caixa, int ano, int ISBN){

    FILE *arquivo;
    arquivo = AbreArquivo('a', "mapa.txt");
    fprintf(arquivo, " %s; %s; %s; %d %d %d\n", titulo, autor, editora, caixa, ano, ISBN);
    FecharArquivo(arquivo);
}

void Listar(){
    FILE *arquivo;
    char titulo[70];
    char autor[70];
    char editora[70];
    int caixa;
    int ano;
    int ISBN;
    arquivo = AbreArquivo('l',"mapa.txt");
    while(fgets(titulo, 2, arquivo) != NULL){
    fscanf(arquivo," %70[^\n] %70[^\n] %70[^\n] %d %d %d\n", &titulo, &autor, &editora, &caixa, &ano, &ISBN);
        setbuf(stdin,NULL);
        for(int i=0; i<120; i++)printf ("*");
        printf("\nTitulo:  %s -  Autor:  %s  - Editora:  %s  - Caixa:  %d  - Ano:  %d  - ISBN:  %d\n\n", titulo,editora ,autor , caixa, ano, ISBN);

}
    FecharArquivo(arquivo);
}
int main(){

    char titulo[70];
    char autor[100];
    char editora[70];
    int caixa;
    int ano;
    int ISBN;
    int opcao;


    
    menu();
    do{

        printf("\nDigite uma opcao: ");
        scanf("%d", &opcao);
        system("cls");

        switch(opcao){
            case 1:

                printf("\nDigite o titulo:  ");
                setbuf(stdin,NULL);
                fgets(titulo, 100, stdin);

                printf("\nDigite o autor:  ");
                setbuf(stdin,NULL);
                fgets(autor,70, stdin);

                printf("\nDigite o editora:  ");
                setbuf(stdin,NULL);
                fgets(editora, 70, stdin);

                printf("\nDigite a caixa:  ");
                scanf("%d", &caixa);

                printf("\nDigite o ano:  ");
                scanf("%d", &ano);

                printf("\nDigite o ISBN:  ");
                scanf("%d", &ISBN);
                Cadastra(titulo, autor, editora, caixa, ano, ISBN);
                system("pause");
                break;

            case 2:
                Listar();
               system("pause");
                break;

            case 3:
                Listar();
                //system("pause");
                break;

            case 4:
                Listar();
               // system("pause");
                break;

            case 0:
                printf("Finalizando......\n");
                system("pause");
                exit(0);

            default:
                printf("\n\nOpcao invalida! Tente Novamente!\n\n");
                system("pause");

        }
    }while(opcao!=0);

    return 0;
}
  • Everything indicates that it is a problem with your monitor.

1 answer

0

Hello, all good?

Well, I took a look at your code here, and it showed no error.

I don’t know if this will help, but it goes like this: in the printf, put a hyphen, then it will eat the hyphen and the text will continue.

Also try to reinstall your IDE, it might help.

I know this is not a very good solution, but maybe I can help. I’m sorry if I was rude, it’s just that I could think of this solution. A good afternoon, evening or good day, depending on the time you are seeing this.

Browser other questions tagged

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