I am trying to implement my own atoi function, and I am supposed to pass my variables in after ./a.out.
Here is my code:
#include <stdio.h>
#include <stdlib.h>
int myatoi(char array[])
{
int sum = 0;
int i = 0;
while(array[i] != '\0') {
int number = array[i] - '0';
sum = 10 * sum + number;
i++;
}
return sum;
}
int main(int argc, char *Name[]) {
/* char *Name = "Josh"; */
printf("%d",myatoi(Name));
return 0;
}
I am getting an error message:
myatoi.c: In function âmainâ:
myatoi.c:20: warning: passing argument 1 of âmyatoiâ from incompatible pointer type
This is in the printf statement. What am I doing wrong?
Also, the program works if I take out the arguments into main and uncomment the first line of main.