From: Rob Zook <rzook@informix.com>
Subject: Strange errors from strtok()
Date: Mon, 01 Dec 1997 13:03:09 -0600 [thread overview]
Message-ID: <3.0.5.32.19971201130309.00913100@atlas> (raw)
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 <stdio.h>
#include <stdlib.h>
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("<HTML>\n<BODY>\n");
printf("<B>CONTENT LENGTH</B> = %d<BR>\n",
atoi(getenv("CONTENT_LENGTH")));
while(gets(postline)!= NULL)
{
printf("%s<BR>\n", postline);
tokenPtr = strtok(postline,"&");<<<<<<<<
do
{
printf("<B>TokenPtr</B> = %s<BR>\n", tokenPtr);
}
while((tokenPtr = strtok(NULL,'&'))==NULL); <<<<<<<<<
}
printf("</BODY>\n</HTML>\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
next prev parent reply other threads:[~1997-12-01 19:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <01bcfe7f$60288060$323ccbd0@zeke.bainet.com>
1997-12-01 18:42 ` Unable to set UDB serial port speed RedHat4.2/2.0.30 Joakim Roubert
1997-12-01 19:03 ` Rob Zook [this message]
1997-12-01 19:51 ` Strange errors from strtok() Richard Henderson
1997-12-01 20:14 ` Michal Jaegermann
[not found] <19971201115108.03468@dot.cygnus.com>
1997-12-01 20:16 ` Rob Zook
[not found] <199712012014.NAA14201@ellpspace.math.ualberta.ca>
1997-12-01 20:37 ` Rob Zook
1997-12-01 22:15 ` Michal Jaegermann
1997-12-01 21:09 Przemek Klosowski
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox