Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
loop running infinite time after calling display function
do
{
    printf("1 :Enter Company Deatils\n");
    printf("2 :Display stoke Deatils\n");
    printf("0 :Exit\n");
    printf("\nEnter num: ");
    scanf("%d", &n);
    switch (n)
    {
        case 1:
            enter();
            break;
        case 2:
            display();
            break;
    }
}
while (n != 0);

When I enter 2 to call display function after that scanf() not taking any input and running loop for infinite time.

void display_d(){
    point c1;
    FILE *fptr;
    fptr = fopen("company_det.txt","r");
    while(fread(&c1,sizeof(point),1,fptr)){
        printf("\n%s %s %d\n",c1.company_name,c1.bla.date,c1.bla.price);
    }
    fclose(stdin);
}

this is my display function

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The function display_d() closes stdin. When the function returns, scanf will try to use stdin to read another digit. This is undefined behavior (see answers here).

You probably meant to close the file instead of stdin.

Also, the return value of fopen should be checked. It will be NULL if fopen failed to open the file.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda