Thread: Comapring values in an array.

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    145

    Comapring values in an array.

    I'm reading in a test file and storing the information into a 2d array (declared with char array[99][99]

    I've then passed this array to another funtion and am comparing it to something and I'm getting compilation errors.

    Here is the line of code:

    while(array[i][b] != 32);

    And here is the error - 16 C:\Documents and Settings\Chrisss\My Documents\C\test.c invalid use of array with unspecified bounds

    What am I doing wrong?

    Thanks for any help

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You're going to have to show more code than that. Maybe the way you're calling the function and then the entire function in which the error occurs.
    If you understand what you're doing, you're not learning anything.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    No idea - post more code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    145
    Ok well here is the full code so far:

    Code:
    #include <stdio.h>
    
    void parse(char array[][],int a)
    {
         int z = 0;
         int b = 0;
         int i = 0;
         char string1[100];
         char string2[100];
         char string3[100];
         char string4[100];
         for(i=0;i<a;i++)
         {
                         b=0;
                         z=0;
               while(array[i][b] != 32)
               {
                      string1[z] = array[i][b];     
                      b++;
                      z++;
                      }
                      
                          
    }                    
     }
    
    
    int main(int argc, char *argv[])
    {
        int x;
        int a = 0;
        int b = 0;
        FILE *fp;
        char array[99][99];
        fp = fopen(argv[1], "r");
        while ( (x = fgetc(fp)) != EOF)
         {
               if(x == ';'){
                    array[a][b] = x;
                    b=0;
                    a++;
                    while ( (x = fgetc(fp)) && (x !=EOF))
                    {
                          if(x == 10)
                          {   
                               break;
                          }
                          
                    }
               }
    
               else
               {
                   if(x == 10)
                   {
                        array[a][b] = '\n';
                        a++;
                        b=0;
                        
                   }
                   else
                   {
                        array[a][b] = x;
                        b++;
                   }
               }
          }   
          parse(array,a);       
    }

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >void parse(char array[][],int a)
    Only the size of the first dimension can be omitted. Every other dimension needs to be filled and correct:
    Code:
    void parse(char array[][99],int a)
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    145
    Excellent, cheers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-19-2008, 02:36 PM
  2. Count distinct array values
    By rkooij in forum C Programming
    Replies: 4
    Last Post: 10-03-2006, 03:03 AM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  5. Duplicate values in Array
    By TONYMX3 in forum C++ Programming
    Replies: 2
    Last Post: 01-30-2002, 03:57 PM