| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Pointers |
Hello Darin!
01 Sep 03 14:01, you wrote to me:
BS>> Can't i avoid to have a extra pointer?
DM> Yes. But not in C. Okay, that's not entirely true - you'd have to
DM> make significant changes, which are not always an option. If you
DM> wrote both the caller and callee, then these changes are what I'd
DM> suggest anyway, even in C++.
Hmm.. I looks like it would be easier with the extra pointer.
KK>>> #include
KK>>> #include
DM> char* test(char** buf, size_t buflen)
KK>>> {
DM> /* char* tmp = (char*)malloc(80); */
DM> /* if(tmp) sprintf(tmp, "test"); */
DM> char* source = "test";
DM> if (buflen > strlen(source))
DM> sprintf(*buf, source);
DM> /* return tmp; */
DM> return *buf;
KK>>> }
KK>>> int main()
KK>>> {
DM> char buf[16];
DM> printf("%s\n", test(buf, sizeof(buf)));
KK>>> fgets(buf, 16, stdin);
KK>>> return 0;
KK>>> }
DM> No malloc/free's here.
No i see thank you :)
Regards,
Bo
--- GoldED+/LNX 1.1.5
* Origin: The Night Express, Roennede Dk (2:236/100)SEEN-BY: 633/267 270 @PATH: 236/100 237/9 20/11 106/1 2000 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™.