- #1
- 4,652
- 37
Hello all,
I am stuck on a little problem. I need to figure out how to return a pointer from a function I am calling and pass it back to the main function. For instance in the example below, I print the address of the first character of a string and then I call a function which increments the pointer to the next address and then prints that address. What I would really like to do is pass the pointer out of the called function and then have the main function print the address of the returned pointer.
I had tried previously set up the main function to take a returned char:
void main(char)
and to set up my nextaddress() function to return a char:
char nextaddress(char* s)
to return s from the nextaddress() function:
return s;
but I didn't have any luck.
What's the proper way to return the pointer to main().
Thanks.
I am stuck on a little problem. I need to figure out how to return a pointer from a function I am calling and pass it back to the main function. For instance in the example below, I print the address of the first character of a string and then I call a function which increments the pointer to the next address and then prints that address. What I would really like to do is pass the pointer out of the called function and then have the main function print the address of the returned pointer.
PHP:
#include <stdio.h>
void nextaddress(char* s);
void main(void)
{
char thestring[] = "Jessica";
printf("now pointing to address %p \n",thestring); //print 1st addr
nextaddress(thestring);
}
void nextaddress(char* s)
{
s++;
printf("now pointing to address %p \n",s); //print next addr
}
I had tried previously set up the main function to take a returned char:
void main(char)
and to set up my nextaddress() function to return a char:
char nextaddress(char* s)
to return s from the nextaddress() function:
return s;
but I didn't have any luck.
What's the proper way to return the pointer to main().
Thanks.