strtok part II - the continuing saga...

strtok part II - the continuing saga...

Post by Eli K. Bu » Fri, 24 Apr 1992 02:18:35



I received alot of responces from my first post on
comp.lang.c -but-

Is there an ftp site where I get docs that talk about the str
functions??? I am hesitating to purchance anything - afterall
I don't understand what is going on (yet).

scorecard for 5 mailed programs sent to me:

             NeXT            Vax
              cc             vcc (ansi)
      =================================
prog 1        ok       |     ok        
prog 2     bus error   |     ok
prog 3     bus error   |     ok
prog 4     no compile  |  no compile
prog 5        ok       | runtime error

notes:
  program 2 and program 3 are mysteries to me

  program 4 used the function strdup which is not supported on
  the NeXT or Vax as far as I know.

  program 5 had a few typo's that I fixed which may have
  resulted in the program working in one environment and not
  another.

##### SAMPLE
Here is the 3rd program which didn't work on the NeXT, but did work
on the Vax.

#include <string.h>
main()
{
   char *p;

   p = strtok("The summer soldier, the sunshine patriot", " ");
   printf(p);
   do {
      p = strtok('\0', ", ");
      if (p) printf("|%s", p);
   } while(p);

Quote:}

--
Eli Burk                   Where were you?
P.O. Box 22135             --If I told you, you wouldn't understand...
San Francisco, CA 94122    (quizzical look)
                           --I was trapped near the inner circle of fault.
email & NeXT mail:         I don't understand.

Life"*
 
 
 

strtok part II - the continuing saga...

Post by Guy Harr » Fri, 24 Apr 1992 11:09:41


(More of a C issue than a UNIX issue, at this point

Quote:>  program 2 and program 3 are mysteries to me

Well, program 2 is a mystery to me, as well, as it wasn't part of your
post, so I've no idea what it contains.

However, program 3 might be easily explicable:

    p = strtok("The summer soldier, the sunshine patriot", " ");

From the SunOS 4.1.1 STRING(3) (which is pretty much based on the SV
STRING(3), and SV is whence its "strtok()", and possibly other
"strtok()"s, came):

     strtok() considers the string s1 to consist of a sequence of
     zero  or  more text tokens separated by spans of one or more
     characters from the separator string  s2.   The  first  call
     (with  pointer  s1 specified) returns a pointer to the first
     character of the first token, and will have written  a  null
     character  into s1 immediately following the returned token.

Note the "will have written a null character into s1".  Well, if your C
implementation makes string *constants* non-writable, your sample
program will lose big, obviously; "strtok()", when it tries to write
into the string constant you fed it, will barf.

The ANSI C standard also indicates that "strtok()" writes into its first
argument.

I think GCC (which is, as far as I know, the C compiler used by NeXT)
makes string constants non-writable, by default; I think you have to use
"-fwritable-strings" to make them writable.

I'm not sure where it explicity says in the ANSI C standard that string
literals are *not* necessarily writable; it implies that is the case in
F.5 "Common Extensions" in that it lists, as a common extension:

        F5.5 Writable String Literals

           String literals are modifiable. ...

Quote:>  program 4 used the function strdup which is not supported on
>  the NeXT or Vax as far as I know.

        char *
        strdup(const char *s)
        {
                register char *p;

                p = malloc(strlen(s) + 1);
                if (p != NULL)
                        (void) strcpy(p, s);
                return p;
        }

Add whatever #includes are needed to get "strcpy()", "strlen()",
"malloc()", and "NULL" defined, and modify as needed if VAX C doesn't
support function prototypes.

 
 
 

strtok part II - the continuing saga...

Post by Werner Fle » Fri, 24 Apr 1992 18:50:49



: I received alot of responces from my first post on
: comp.lang.c -but-
:
: ##### SAMPLE
: Here is the 3rd program which didn't work on the NeXT, but did work
: on the Vax.
:
: <lines deleted>
:
: #include <string.h>
: main()
: {
:    char *p;
:
:    p = strtok("The summer soldier, the sunshine patriot", " ");
:    printf(p);
:    do {
:       p = strtok('\0', ", ");
                   ====
:       if (p) printf("|%s", p);
:    } while(p);
: }
:

The first argument to strtok is a char* and not a char. Use
       p = strtok((char *)0, ", ");
and it should work because on some compilers sizeof(char)!=sizeof(char*).

--

* Technische Universitaet Hamburg-Harburg, Arbeitsbereich Fertigungstechnik I *
* Denickestrasse 17, 2100 Hamburg 90, Tel.: 040/7718-3286, Fax: 040/7718-2500 *

 
 
 

1. Linux questions & problems Part II (continued)

  Hi All! I'm having some problems with MCC linux and the latest linux
kernel. I just got the p13 kernel and compiled it. After I got down to the
"make zImage" command and completed it, I did this:
     1. cp /usr/src/linux/zImage
     2. copied zImage to where /etc/lilo/config pointed to as "Image" instead
        of "zImage" (Because config says "Image" and not "zImage")
     3. Ran "/etc/lilo/install"

 Now, when I boot up with Linux (from my HD) it still says p10 instead of p13
and it locks up shortly after I log in. I have 2 more files left named
"zBoot" and "zSystem.map". What should I do with them? What is going on here?
What do I need to do to make this thing work? I'm very frustrated as I have
worked my whole weekend in this thing with no result and I'm about to format
my HD and toss Linux out of it..:-( Very good system but too much trouble for
a starter like me. It just disappoints me. Any1 cares to help a dismoralized
user out? (That's me, of course!) :-( BTW, I installed everything with the
defaults and Linux, once it boots it keeps checking the disk as if it was
peforming a chkdsk-like command.
--


|               Hey Waitress! There's a pubic hair in my soup!              |
|             "Don't give up, don't ever give up" - Jim Valvano             |

2. ULTRA DMA and RH5.2 Kernal Patch Needed ?

3. The Networking Saga Continues...

4. Problem in activating Lan card in Redhat 8.0

5. Installing xfce: the saga continues (or I'm too stupid for Linux)

6. MAINTAINERS file - DIGI EPCA driver

7. The PPP Saga Continues

8. re bash script help

9. PS/2 mouse: Day 2, the Saga continues ... please help!

10. HA... the saga continues (found a binary)

11. RH6.0 installs, but won't boot - saga continues

12. The SAR saga continues

13. The Mosaic saga continues ....