samedi 25 septembre 2021

Only specific to be as input in function

I'm using a function to get an specific number to my switch in C. The specific number should be between 0-12. This is the code I have:

int mataintal(){
  int i, b;
  char buffer[BUFFSIZE];

do{
  b = 0;
  scanf("%s", buffer);
  for(i=0;  i < strlen(buffer); i++){
      if (!isdigit(buffer[i]))
      b = 1;
  }
} while(b == 1);

This code part works fine. But when I add && to the if statement the code stops working and just makes a to 1 and returns the input variable. How can I fix this?

Aucun commentaire:

Enregistrer un commentaire