| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | call by reference??? |
PT> void doit(char *teststring)
PT> {
PT> teststring = NULL;
PT> }
PT> void main( void )
PT> {
PT> char *mystring = "blabla";
PT> doit(mystring);
PT> }
PT> OK this works - and at the very same moment , it doesn't
PT> ;-) I mean : it doesn't crash, but it doesn't do what I
PT> want it to do: when returning from the call to doit ,
PT> mystring still contains "blabla" and I want it to contain
PT> NULL...
PT> How can I change that 'teststring' argument 'permanently'?
doit() is given a pointer to the stringspace.
If you want to effect the stringspace, you must dereference
the pointer, either by means of pointer notation or array
notation.
*teststring = (char)'\0';
teststring[0] = (char)'\0';
If you want to redifine the pointer itself, then you should
realize that the variable teststring and the variable
mystring are two separate variables. You can change the
value of mystring by returning a pointer value.
char* doit(char *teststring)
{
teststring = NULL;
return teststring;
}
void main( void )
{
char *mystring = "blabla";
mystring = doit(mystring);
}
> ] * Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)SEEN-BY: 396/1 622/419 632/0 371 633/260 267 270 371 634/397 635/506 728 810 SEEN-BY: 639/252 670/213 218 @PATH: 154/750 222 396/1 633/260 635/506 728 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.