two dimensional character array

This is a discussion on two dimensional character array within the C Programming forums, part of the General Programming Boards category; error - arithmetic on pointer to an incomplete type - on statements like this... string[i][1] = c; message[j] != string[k][0] ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    3

    two dimensional character array

    error - arithmetic on pointer to an incomplete type - on statements like this...

    string[i][1] = c;
    message[j] != string[k][0]

    string is a two dimensional character arrays, [string (33,2)] message is a one dimension character array. any and all help would be appreciated.

    edit: i can post entire code if necessary
    Last edited by feuerraeder; 11-21-2002 at 05:36 PM.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    5
    Feuerraeder, some confusion here, You appear to be comparing chars from different strings, but it's difficult to see what you are trying to achieve.
    Just as a guess to what you are trying to do - The strcmp function can be used for comparing whole strings, strcmp(*str1, str2) = 0 if they are equal, non zero otherwise, ie strcmp(message, string[k]).

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    string[i][1] = c;
    Since you've stated that 'string', which is a reserved keyword by the way, and you shouldn't use that name, is a two dimensional character array, and unless you have a char variable declared as c, your assignment is incorrect.

    What is c? Is it a variable, or are you trying to assign the letter c to that spot in the array? If it isn't a variable, then you need to be doing:

    array[i][1] = 'c';

    Otherwise, without knowing what exactly is taking place, we can only guess.

    [edit]
    message[j] != string[k][0]
    Furthermore, what is this line? Is this line in an if statement for comparison? If not, this line is also invalid.

    Valid:

    if( array[x] != array2[y] )

    Invalid:

    array[x] != array2[y];


    The operator != cannot be used for assignment. It is strictly used for comparisons.
    [/edit]

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

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    3
    i've renamed the array from 'string' to 'key'

    c is a char variable

    and the != was part of an if statement...

    full code:

    Code:
    #include<stdio.h>
    #include<ctype.h>
    #include<string.h>
    
       void readCode(char [][]);
       void encode(char [][]);
       void decode(char [][]);
    
        int main()
       {
          char c, key[33][2] = { {'A','0'}, {'B','0'}, {'C','0'}, {'D','0'}, 
          {'E','0'}, {'F','0'}, {'G','0'}, {'H','0'}, {'I','0'}, {'J','0'}, 
          {'K','0'}, {'L','0'}, {'M','0'}, {'N','0'}, {'O','0'}, {'P','0'}, 
          {'Q','0'}, {'R','0'}, {'S','0'}, {'T','0'}, {'U','0'}, {'V','0'}, 
          {'W','0'}, {'X','0'}, {'Y','0'}, {'Z','0'}, {' ','0'}, {'.','0'}, 
          {',','0'}, {'?','0'}, {'!','0'}, {';','0'}};
       
       
          readCode(key);
       
          printf("\n\n     MENU\n\n");
          printf("C    Change Code\n");
          printf("E    Encode\n");
          printf("D    Decode\n");
          printf("Q    Quit\n"); 
          
          scanf("%c",c);
          toupper(c);
       	
          switch(c)
          {
             case 'C':
                readCode(key);
                break;
             case 'E':
                encode(key);
                break;
             case 'D':
                decode(key);
                break;
             case 'Q':
                printf("Goodbye\n");
                break;
          }
       
          return 0;
       }
       
    	
        void readCode(char key[][])
       {
          char c, code[33];
          int  i = 0;
          
          printf("Enter the code, you must enter 32 unique characters on one line\n");  
          
          for(i = 0; (c = getchar()) != '\n'; i++)
               key[i][1] = c;
                 
       }
       
        void encode(char key[][])
       {
          char c, message[100];
          int i = 0, j = 0, k = 0;
       
          printf("Enter the string to be encoded, press enter when finished\n");
          for(i = 0; (c = getchar()) != '\n'; i++)
             message[i] = c;  
          
          printf("Encoded Message\n");
       	
          for (j = 0; j < i; j++)
          {
          
             while (message[j] != key[k][0])
                k++;
          	
             putchar(key[1][k]);
             k = 0;
          }
          printf("\n");
       }
       
        void decode(char key [][])
       {
          char c, message[100];
          int i = 0, j = 0, k = 0;
       
          printf("Enter the string to be decoded, press enter when finished\n");
          for(i = 0; (c = getchar()) != '\n'; i++)
             message[i] = c;  
          
          printf("Decoded Message\n");
       	
          for (j = 0; j < i; j++)
          {
          
             while (message[j] != key[k][1])
                k++;
          	
             putchar(key[0][k]);
             k = 0;
          }
          printf("\n");
       
       }
    errors are in bold, but kinda hard to see
    Last edited by feuerraeder; 11-21-2002 at 10:13 PM.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    3
    thank you kindly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using a character array in a switch question.
    By bajanElf in forum C Programming
    Replies: 10
    Last Post: 11-08-2008, 07:06 AM
  2. Scanf confusion, 2 dimensional array modification
    By Leojeen in forum C Programming
    Replies: 23
    Last Post: 10-19-2008, 10:58 PM
  3. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  4. Character Array comparison
    By magda3227 in forum C Programming
    Replies: 7
    Last Post: 07-09-2008, 08:36 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM

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