How to do validation for input? number or alphabet.. C programming -


set1: printf("name            : "); gets (name); if (isalpha(name)) {printf("\nsorry, input invalid\n"); goto set1;} 

this piece of code, , declared name char name [30]; but, says error argument of type *char incompatible parameter type int.. , how validate if input randomly alphabet , number (e.g gghjhj88888)?

thank helping?

#include <stdio.h> #include <string.h> #include <ctype.h>  int isdigits(char *s){     //return value : true if string numbers.     while(*s)         if(!isdigit(*s++))             return 0;     return 1; }  int main(void){     char dateofbirth[7];     int len; set4:     printf("date of birth (ddmmyy)  : ");     //doesn't accept input more specified number of characters     fgets(dateofbirth, sizeof(dateofbirth), stdin);     rewind(stdin);//keyborad buffer flush     //fflush(stdin);//discard character exceeding amount of input     //how fflush work stdin processing system (that undefined)     //while ('\n' != fgetc(stdin));//skip if on inputted     len = strlen(dateofbirth);     if(dateofbirth[len-1] == '\n') dateofbirth[--len] = '\0';//newline drop     if(len != 6 || !isdigits(dateofbirth)){         printf("\nsorry, input invalid\n");         goto set4;     }      return 0; } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -