小编Fra*_*cha的帖子

在C上避免此错误的正确方法是什么

我有这个代码,我想知道为什么我的代码跳过scanf ...

#include <stdio.h>

char nombre[20];
int tipo;
int edad;
int dias;

int repetir=0;

int main()
{

   while (repetir==0){
        int error=0;
        do{


            printf("Diga su Nombre: ");
            scanf("%19[^\n]", nombre);
            printf("Diga el tipo de Sala: ");
            scanf("%d", & tipo);
            printf("Diga la edad del Paciente: ");
            scanf("%d", & edad);
            printf("Dias de Hospitalizacion: ");
            scanf("%d", & dias);

            if ((tipo>4) || (tipo<0) || (edad<0) || (dias <0) ){
                printf("Eror al ingresar los datos");
            } else {
                error = 1;
            }
        }
        while(error==0);

        printf("¿Algun otro paciente? …
Run Code Online (Sandbox Code Playgroud)

c string loops

-2
推荐指数
1
解决办法
88
查看次数

标签 统计

c ×1

loops ×1

string ×1