I'm 3 weeks into CS50 and have spent a full day trying to get atoi to work. I'm getting the below error when compiling the below code.
My questions are:
- How do I represent each single character in the atoi() function?
- How do I only print the results only once? (the loop is making it print the number times of argv when I change atoi to argv[1])
Much thanks to the community in advance. I am eagerly to becoming a good programmer.
========= caesar.c:22:30: error: incompatible integer to pointer conversion passing 'char' to parameter of type 'const char *'; take the address with & [-Werror,-Wint-conversion] int a = atoi(argv[1][i]); ^~~~~~~~~~
int main(int argc, string argv[])
{
//if not exactly 1 argument, print error message a value of 1
if (argc == 2)
{
for (int i = 0; i < strlen(argv[1]); i++)
{
if (!isdigit(argv[1][i]))
{
printf("Usage: ./caesar key\n");
return 1;
}
else
{
int a = atoi(argv[1][i]);
printf("%i\n",a);
}
}
}
else
{
printf("Usage: ./caesar key\n");
}