Comparing elements of character pointer arrays

This is a discussion on Comparing elements of character pointer arrays within the C Programming forums, part of the General Programming Boards category; Code: I have arrays *arr and *aqq. I am trying to find the occurence of similar elements(strings) in the arrays... ...

  1. #1
    axe
    axe is offline
    Registered User
    Join Date
    Jan 2006
    Posts
    33

    Comparing elements of character pointer arrays

    Code:
    I have arrays *arr and *aqq. I am trying to find the occurence of similar elements(strings) in the arrays...  
    
    this won't work..
       for(i=0;i<=count;i++)
       {
         found=0;
         for(j=0;j<=k;j++)
         {
           if(&arr[j]==&aqq[i])
           {
             found++;
           }
         }
     }
    
    and also this won't work...
    
       for(i=0;i<=count;i++)
       {
         found=0;
         for(j=0;j<=k;j++)
         {
           if(strcmp(arr[j],aqq[i])==0)
           {
             found++;
           }
         }
    }

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Post a larger snippet, like how you declare the arrays (and fill them), also stop posting your entire post in code tags!

    If you want to find strings in strings use strstr(), and what do you mean "this won't work"?

  3. #3
    axe
    axe is offline
    Registered User
    Join Date
    Jan 2006
    Posts
    33
    here are the array declarations... don't know how to stop posting entire post in code tags..


    Code:
      char *arr[30000];
    
      temp=strtok(NULL,delimiters);
        arr[k]= (char*)temp;
      
       char *aqq[30000];
    
       while(fgets(c,sizeof(c),fq)!=NULL)
       {
         aqq[count]=c; count++;
       }
       int found;
       for(i=0;i<=count;i++)
       {
         found=0;
         for(j=0;j<=k;j++)
         {
           if(strstr(arr[j],aqq[i])==0)
           {
             found++;
           }
         }
    Last edited by Salem; 11-14-2007 at 02:07 AM. Reason: Put [code][/code] around only those bits you need

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Comparing Pointer types in C
    By ladesidude in forum C Programming
    Replies: 16
    Last Post: 07-15-2008, 10:34 PM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 11:10 AM
  3. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 04:20 AM
  4. Help with pointer arrays please
    By Nutcasey in forum C Programming
    Replies: 2
    Last Post: 12-14-2003, 05:04 PM
  5. Pointer of arrays - how do I access their elements?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-12-2001, 12:28 AM

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