Hello I'm attempting to convert a char into an int. I have a char array that was inputted through scanf, "10101" and I want to set an int array's elements equal to that char arrays elements.
example input:
10101
char aBuff[11] = {'\0'};
int aDork[5] = {0};
scanf("%s", aBuff); //aBuff is not equal to 10101, printing aBuff[0] = 1, aBuff[1] = 0 and so on
Now I want aDork[0] to equal aBuff[0] which would be 1.
Below is what I have so far.
//seems to not be working here
//I want aDork[0] to = aBuff[0] which would be 1
//But aDork[0] is = 10101 which is the entire string of aBuff
//aBuff is a char array that equals 10101
//aDork is an int array set with all elements set to 0
int aDork[5] = {0}
printf("aBuff[0] = %c\n", aBuff[0]); //value is 1
aDork[0] = atoi(&aBuff[0]); //why doesnt this print 1? Currently prints 10101
printf("aDork[0] = %d\n", aDork[0]); //this prints 1
printf("aBuff[1] = %c\n", aBuff[1]); //this prints 0
printf("aBuff[2] = %c\n", aBuff[2]); //this prints 1
atoi.