Getting string after certain character

This is a discussion on Getting string after certain character within the C Programming forums, part of the General Programming Boards category; char hello[]= "main(int"; How can i extract the "int" from the hello string?? I know the length of the string ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    41

    Getting string after certain character

    char hello[]= "main(int";

    How can i extract the "int" from the hello string??
    I know the length of the string which is 8 and i know that the "(" start in position 5. From there, how can i proceed in getting the rest of the character after the "(" ??

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If you know it's at a given position, then do:
    Code:
    #define OFFSET 5 /* or whatever it is */
    char hello[] = "main(int";
    char *ptr = hello + OFFSET;
    
    printf("%s", ptr );
    That's one way to do it. Another way would be to simply loop through checking each character until you found what you're looking for, and then go from there. You could use the standard string functions to aid you. There are lots of ways to do it.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 02:02 AM
  2. Remove character from string
    By nooksooncau in forum C Programming
    Replies: 11
    Last Post: 06-05-2006, 10:37 AM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 10:19 AM
  4. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM

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