From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <3.0.5.32.19971201130309.00913100@atlas> Date: Mon, 01 Dec 1997 13:03:09 -0600 From: Rob Zook Subject: Strange errors from strtok() In-Reply-To: <01bcfe7f$60288060$323ccbd0@zeke.bainet.com> Hi all, Hopefully, someone here has done some c programming on these Alphas. I have a UDB and I'm running RedHat 4.1 w/ some of the RedHat 4.2 upgrades. I'm trying to use the strtok function from stdlib in a program and I get these strange errors: #include #include main() { char postline[80]; char tokenName[10][80]; char tokenValue[10][80]; char Name[30]; char Extension[9]; char Friend[5]; char *tokenPtr; printf("Content-type: text/html\n\n"); printf("\n\n"); printf("CONTENT LENGTH = %d
\n", atoi(getenv("CONTENT_LENGTH"))); while(gets(postline)!= NULL) { printf("%s
\n", postline); tokenPtr = strtok(postline,"&");<<<<<<<< do { printf("TokenPtr = %s
\n", tokenPtr); } while((tokenPtr = strtok(NULL,'&'))==NULL); <<<<<<<<< } printf("\n\n"); } When I try to compile this program I get the following warnings: [rzook@babylon5 cgi-bin]$ cc -o rsvp rsvp.c rsvp.c: In function `main': rsvp.c:20: warning: assignment makes pointer from integer without a cast rsvp.c:25: warning: assignment makes pointer from integer without a cast /tmp/cca197261.o: In function `main': rsvp.c(.text+0x8c): the `gets' function is dangerous and should not be used. In the above program lines 20 and 25 are marked with the "<<<<<<<". I'm not sure why I'd get these warnings. cc produces an executable, but When I run this cgi program from my web form, it produces a server error. If I add a fflush(stdout), just before the do loop, the server error goes away and I get some output. However, the execution only goes thru the do loop once, and then next call to strtok evidently returns a NULL. The results of the program with the fflush(stdout) look like this: CONTENT LENGTH = 52 name=Rob+Zook&extension=1111&guest=yes&beverage=beer TokenPtr = name=Rob+Zook As you can see the returned postline has 52 characters in it, and with a call to strtok like: tokenPtr = strtok(NULL,'&') I should get 4 tokens back. But I only get one. To summarize: 1. Why do the warnings occur? 2. Why does my loop fail on the second call to strtok? Thanks, Rob Z. -------------------------------------------------------- Not reaching a goal on a given day does not preclude reaching it tomorrow, or next year. One failure does not mean all is lost. Let it be motivation to improve, to deliver optimum performance in the next undertaking, whatever it may be - not to give up and quit trying. -- Capt. Spock -- To unsubscribe: send e-mail to axp-list-request@redhat.com with 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com