Thread: C newbie

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Taipei
    Posts
    70
    Rep Power
    11

    C newbie


    i know in java we can catch some characters inside an array (using substring), can we do it too in C?

    ex: array[]="blueberry";/*can we take out the "blue"?*/
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    31
    Rep Power
    11
    halo

    u may want to chk out string.h... or if u are in linux/unix, chk out its man pages....

    loads of char* manipulation functions there. (in my opinion more than what java offers...,but thats just my own humble opinion)
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    55
    Rep Power
    11
    You can't take it out, you can copy part of the values in memory you want to keep somewhere else, or access the section you want with another pointer etc...

    Code:
    char *str = "Blueberry";
    str+= 4;
    printf("str = %s\n", str);
    Code:
    char str[] = "Blueberry";
    char *ptr;
    
    ptr = str+4;
    printf("ptr = %s\n", ptr);
    I would imagine most people would think the second is more correct, you aren't hinting that the allocated memory for the character array should be partly forgotten about.

IMN logo majestic logo threadwatch logo seochat tools logo