Substrings, how would I use this function?

This is a discussion on Substrings, how would I use this function? within the C Programming forums, part of the General Programming Boards category; Code: strstr(char* dest, char* src){ } Is that the normal format? Cheers...

  1. #1
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463

    Substrings, how would I use this function?

    Code:
    strstr(char* dest, char* src){
    
    }
    Is that the normal format?

    Cheers

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,849
    What about the return result?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    This is giving me a comparison between integer and pointer warning.

    Code:
    if  (strstr(node->name, command) == 1){
              curr = node;
              printf("%s\n", curr->name);
     }
    How must I put the truth value? Like...what are the return parameters or something I can check to see if the substring exists?

    Cheers

  4. #4
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Quote Originally Posted by Salem View Post
    What about the return result?
    Oh I didn't mean to make it into a function like that, it's already a library function.

    So I can just call it like strstr(dest*, src*);

    How do i deal with the return value on that? Or where is it going, not quite sure

  5. #5
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Nvm, the return value is == 0 I see.

    solved

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,849
    The return value is a char* pointer to the match, or NULL.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  4. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 07:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21