rajus schrieb:
How to convert a char array to an int array?So if
char s[]={"1234"};
then the int array say 'num' should have values num[0]= 1 num[1]=2 and
so on.
Allocate sufficient storage, say with
int *array = malloc(strlen(s) * sizeof *array);
if (array == NULL) {
/* Your error handling here; in its absence: */
exit(EXIT_FAILURE);
}
Then iterate through s, make sure that you have a digit,
e.g. by using isdigit(); if you find a non-digit, terminate,
if the non-digit is not '\0', emit an error message;
whenever you have a digit, convert this digit to the
digit's value (e.g. using "digit - '0'") and store it in
the appropriate element of array.
If your implementation does not work, post your compiling
code here and explain your problem as clear as possible.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.