. , .
#include <stdio.h>
void foo(char cc[])
{
int i;
printf("%p\n",cc);
printf("Type the address you would like to read:");
scanf ("%x",&i);
printf("Character value at your address: %c\n",*((char *)(i)));
}
int main()
{
char c[] = "Hello";
foo(c);
}
This will allow you to read the address provided on the command line. First, it will print out the base address of the character array so that you know where to look for the string.
Example:
$ ./a.out
0xbfcaaf3a
Type the address you would like to read:bfcaaf3d
Character value at your address: l
As expected, this prints the fourth letter Hello.
Lucas source
share