Thread: Search a pattern " ) , (" in string array

  1. #1
    Registered User
    Join Date
    Aug 2011

    Search a pattern " ) , (" in string array

    Is there a way to search a pattern that are C- standard key characters in a string array using strstr function?. e.g :- I want to search for this pattern ),(
    The code lines below works for any patterns like "++++" or "****" in line 100 but not for "),(". Any ideas would help.

    Thank you..

    100:if(((strstr(test_buffer,"),("))!= NULL)!= except)
    102:	parsed_array[i] = (char *) malloc(sizeof(char) * (strlen(test_buffer) + 1));
    103:	strcpy(parsed_array[i],test_buffer);
    104:	i++;

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    If it's not finding it, that's because it isn't there. (Note that spaces are relevant.)

    For instance:
    #include <string>
    int main(void) {
        char *bob = "(Test),(Test)";
        char *answer;
        answer = strstr(bob, "),(");
        printf("The pattern was found at position %u.\n", answer-bob);
        return 0;

  3. #3
    Registered User
    Join Date
    May 2011
    Around 8.3 light-minutes from the Sun
    1. Do not cast malloc. Read Casting malloc-FAQ

    2. What is except?

    3. To check for any string using strstr, it is the same regardless of what you are looking for:
    #include <stdio.h>
    #include <string.h>
    int main(void){
    	char string[]="(where is),(in string";
    	char search[]="),(";
    	char *searchpos=NULL;
    	searchpos = strstr(string,search);
    		printf("\"%s\" contains \"%s\" ",string,search);
    		printf("Substring not found");
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 46
    Last Post: 08-24-2007, 04:52 PM
  2. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  3. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM

Tags for this Thread