i am supposed to read input from stdin in format like "%c %d:%d:%d %d" and allowed character at the beginning are + - #
what i have tried is
while(1){
ret = scanf(" %c %d:%d:%d %d",&c,&h,&m,&s,&id);
if (ret != 5) break;
if(c=='#') {
log++;
abs_prev=-1;
continue;
}else if(c=='+'){}
else if(c=='-'){}
else{
printf("invalid input.\n");
return 0;
}
}
this code fails because when i enter input + 15:00:00 1enterbutton#enterbutton it puts \n character into the variable c which is not matched below and returns 0
here is what my input can look like
+ 8:00:00 100
+ 8:50:00 105
- 9:30:00 100
- 18:20:00 105
- 19:00:00 100
#
- 17:00:00 100
+ 18:00:00 100
#
#
+ 8:00:00 66
+ 9:00:00 200
+ 10:00:00 100
- 15:00:00 200
- 17:30:00 66
what i want to do with it is when first char is + i store data in tree A, if its - i will store it in tree B when its # i create new tree
scanf(" %c %d:%d:%d %d %*c",&c,&h,&m,&s,&id);