Seung Kwak Seung Kwak - 3 months ago 40
C Question

How to check whether a number or not in array on structure in C

there's a structure of arrays like this.

typedef struct
char mother [50];
char father [50];
} family;

family divorce [100];

On this array, I input the number + char (length is random) like 123a 253vv 2145eee..., and I'd like to save only number to the another char array. What should I do?


Use isdigit() to determine whether the character is a decimal digit or not. If the char is a digit, populate it in the array.

Another way, check if(ch >= '0' && ch <= '9') arr[i++] = ch;