I'm trying to write my own scanf function in C using only read/write (no libary functions, no va_args etc.). I came up with this code (only for decimal integers for now):
void myscanf(char* text, ... ) {
char* ap = (char *) &text + sizeof text;
char* p;
int tempk;
for(p=text; *p != '\0'; p++){
if(*p=='%'){
p++;
switch (*p) {
case 'd':
char data[128] = { 0 };
read(0, data, 128);
tempk = StringToInt(data, 10);
int* k = (int*)ap;
*k = tempk;
break;
}
}
}
}
For some reason the address of *k is different from pointer I pass as an argument. I tried different ways, but I sill don't know how to get the right address.