c - Taking user input and using a function to check if its valid -
i'm trying create program in user enters 3 integers, , function checks see input valid. if input not valid, user must input 3 new numbers.
#include <stdio.h> int sanitizedinput(int a, int b, int c) {      if(scanf("%d", &a)==0)      {          printf("not number\n");          return 1;      }      else if(scanf("%d", &b)==0)      {          printf("not number\n");          return 1;      }      else if(scanf("%d", &c) == 0)      {           printf("not number\n");           return 1;      }                       else          return 0; } int main() {      int a;      int b;      int c;      int check = 1;            {          check = 0;            printf("enter number:");           scanf("%d",&a);           printf("enter number:");           scanf("%d",&b);           printf("enter number:");           scanf("%d",&c);            check = sanitizedinput(a,b,c);      }while(check); } however when run code, after entering 3 valid integers nothing shows in terminal , code terminates after entering 6 integers. (there other functions , code in main function, if code necessary find problem tell me , post it.)
your code , writing part not matching.....
- you should check 3 numbers valid or not firstly.
int sanitizedinput(int a, int b, int c) { if(a==0 || b==0 || c==0) { return 1; } else { printf("they valid.....\n"); return 0; } }
then if 1 of them invalid, able take 3 input returning value of 1. because while(1) true condition.
Comments
Post a Comment