Tim,
Thank you.
If we change isdigit to isalpha, and change the atoi function to something as below:
Code:
char atoi(char s[])
{
int i, n, sign;
for (i = 0; isspace(s[i]); i++) /* skip white space */
;
sign = (s[i] == '-') ? -1 : 1;
if (s[i] == '+' || s[i] == '-') /* skip sign */
i++;
for (i = 0; isalpha(s[i]); i++) {
//return sign * n ;
return n;
}
}
Here is the complete code I am using...really just a modification of your solution:
Code:
#include <stdio.h>
#include <ctype.h>
#define MAX 5
char atoi(char a[]);
int main()
{
char val;
char s[MAX] = {'+', '1', '0','0',' '};
// char s[MAX] = {'b', ' ', 'b',' ',' '};
val = atoi(s);
printf("%c\n",val);
return 0;
}
/* atoi: convert s to integer; version 2 */
char atoi(char s[])
{
int i, n, sign;
for (i = 0; isspace(s[i]); i++) /* skip white space */
;
sign = (s[i] == '-') ? -1 : 1;
if (s[i] == '+' || s[i] == '-') /* skip sign */
i++;
for (i = 0; isalpha(s[i]); i++) {
return n;
}
}
Andrew