When is a pointer a pointer but not a pointer but then a pointer
i have the following
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void AddStrings( char *, char *, char * );
int main()
{
unsigned long long x = 399, y = 399;
char strNumberx[20] = { '\0' }, strNumbery[20] = { '\0' }, strResult[21] = { '\0' }; //strresult is 1 more incase of a carry
sprintf( strNumberx, "%llu", x );
sprintf( strNumbery, "%llu", y );
AddStrings( strNumberx, strNumbery, strResult );
printf("%s\n", strResult);
printf("Just to prove you can index strings %c %d\n", strNumberx[0], strNumberx[0]);
return 0;
}
void AddStrings( char *Numx, char *Numy, char *Result )
{
//it is assumed that numx and numy have the same number of digits
int x = 0, y = 0, Carry = 0;
for ( int Answer = 0, i = strlen( Numx ) - 1; i >= 0; i-- )
{
x = atoi( &Numx[i] );
y = atoi( &Numy[i] );
Carry = 0;
Answer += x + y;
if ( Answer > 9 )
{
int tmpNum = Answer;
Answer %= 10;
Carry = (tmpNum - Answer ) / 10;
}
sprintf( &Result[i], "%d", Answer );
Answer = Carry;
}
}
this is what the compiler says
gcc -Wall -g -pedantic -Wall -std=c99 -c "/home/****/Documents/my code/add_2_strings/main.c" -o obj/Debug/main.o
gcc -o bin/Debug/add_2_strings obj/Debug/main.o -lm
Output file is bin/Debug/add_2_strings with size 18.15 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
issue is when i step through the function code on the first iteration x and y both = 9 which is correct how ever on the second and third iteration x and y = 99 or 399 on the third iteration
i have tried replacing &Numx with Numx, *Numx and (*)Numx the first one produces a warning "|29|warning: passing argument 1 of ‘atoi’ makes pointer from integer without a cast [-Wint-conversion]|" 2nd and 3rd ones produce errors