jeudi 8 octobre 2015

problem with scanf c programming language

So I made this program in c language, which supposed takes 2 input using scanf, and if the character part of the input is a specific character, then the counter for that character increases. But, when I run it, the program terminates after 2 times I input an input to the scanf, and it goes straight into the printf statement outside the while loop, with the i value being printed as 1 and the k value printed as 0. I'm not allowed to use anything else other than scanf. Can anyone please help? Thank you

#include <stdio.h>

typedef struct {

    double x;
    } se_t;

typedef struct { 

       double x;
       } ce_t;

int
main(int agrc, char *agrv[]){
ce_t ce[43];
se_t se[43];
double a=0;
int i=0, k=0;
char check;

while ((scanf("%c %lf",&check,&a)==2)){
    if (check=='a'){
    ce[i].x=a;
    i++;
    }
    else if (check=='b'){
    se[k].x=a;
    k++;
    }
}
printf("%d\n",i);
printf("%d\n",k);
return 0;
}

Aucun commentaire:

Enregistrer un commentaire