I’m coding in C and it seems like the program ignores the scanf command and starts doing an infinite cycle if I insert anything other than a number. Does anyone know how to fix it or even what is going on?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define NBITS 8
void inserimento(){
int N, ret;
do {
printf("Immetti un numero maggiore di 1n");
ret = scanf("%d", &N);
}
while(ret==0 || N <= 1);
}
int main(){
int N;
inserimento();
}
I’ve tried switching the order of the or statement and using the solution from the code my professor gave us but I’m pretty new to this so I don’t know if I messed up in copying it.
New contributor
tommaso morlupi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1