Search a pattern " ) , (" in string array

This is a discussion on Search a pattern " ) , (" in string array within the C Programming forums, part of the General Programming Boards category; Is there a way to search a pattern that are C- standard key characters in a string array using strstr ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    3

    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..

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

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

    For instance:
    Code:
    #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
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    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:
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main(void){
    
    	char string[]="(where is),(in string";
    	char search[]="),(";
    	char *searchpos=NULL;
    
    	searchpos = strstr(string,search);
    	if(searchpos)
    		printf("\"%s\" contains \"%s\" ",string,search);
    	else
    		printf("Substring not found");
    
    	getchar();
    	return(0);
    }
    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, 05: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


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