| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Auto string-length deter |
Hi Frank
FA> I don't think you understand what he wants to do, he wants to make a
FA> completely self efficient function, where the function will either resize
FA> or stop if the string passed to it is not big enough for the secific task.
That's what I thought I was suggesting, something like
int myfunc(char *instring)
{
int i;
char *copy, *working;
i = strlen(instring);
/* working is a new empty string the same lenght as instring */
if((working = malloc(i+1)) == NULL) return -1;
/* copy is a new string that is a copy of instring, so we can
change it without annoying the original */
if((copy = malloc(i+1)) == NULL) return -1;
strcpy( copy, instring);
/* do things with the strings here, returning integers as results.
Just ensure that all return statements are preceded by free()
statements, like: */
free(copy);
free(working);
return 0;
}
The original [100] size doesn't have to be passed to the function.
Cheers
--- PPoint 1.88
* Origin: Silicon Heaven (3:711/934.16)SEEN-BY: 711/808 934 @PATH: 711/934 |
|
| 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™.