Thread: Need an idea

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    17

    Need an idea

    Hi i got following problem:

    I get a string which consists of substrings seperated by :
    In fact they can look like one of these

    Code:
    POS:X:DIST:IMM
    POS:DIST:IMM
    POS:IMM
    but these three are comlpetly the same and i have to call the same function afterwards. Now my question is if i have to test in an if question all the three cases or if there is a better way?
    Last edited by Onkel BeBu; 01-07-2004 at 09:26 AM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    POS:X:DIST:IMM
    POS:DIST:IMM
    POS:IMM
    If all three are the same then you really only need the first and last items. Something like this:
    Code:
    char *last = strrchr ( s, ':' ) + 1;
    char *first = strchr ( s, ':' );
    *first = '\0';
    first = s;
    /* Now first points to "POS" and last points to "IMM" */
    Of course, you would need to add error checking. And if the original cannot be modified, some copying would need to be done as well.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    17
    thx i searched for something like that!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. project idea ???
    By gemini_shooter in forum C Programming
    Replies: 2
    Last Post: 06-09-2005, 09:56 AM
  2. Have an idea?
    By B0bDole in forum Projects and Job Recruitment
    Replies: 46
    Last Post: 01-13-2005, 03:25 PM
  3. A little problem about an idea, help please
    By louis_mine in forum C++ Programming
    Replies: 3
    Last Post: 09-10-2004, 09:52 PM
  4. totally screwed up idea
    By iain in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 08-17-2001, 12:09 PM