Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,395 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,120 people online right now. Registration is fast and FREE... Join Now!




count letter problem

 
Reply to this topicStart new topic

count letter problem

Euniceno1
24 Oct, 2006 - 05:40 PM
Post #1

New D.I.C Head
*

Joined: 22 Oct, 2006
Posts: 3


My Contributions
The following are the code That I created:
CODE

#include <stdio.h>
#include <ctype.h>

int main(void)
{
   int c, i, j, letter[26][26];

   for (i=0; i<26; ++i) /* init array to zero */
       letter[i] = 0;
   for( j= 0; j<26; ++j)
           letter[j] = 0;
   while((c = getchar()) != EOF) /* count the letter */
        if(isupper© && islower©)
          ++letter[c -> 'A' && c -> 'a'];
   for (i=0; i<26; ++i)
     if(i%6==0)
   for ( j= 0; j<26; ++j)
     if(j%6==0) {
       printf("\n");
     printf("%4c%4c:%3d%3d", 'A' || 'a' +i +j, letter[i][j]);
   }
   printf("\n\n");
   return 0;
}

and the error I got from the gcc compiler:
letter1.c:In function 'main':
letter1.c:9:error: incompatible types in assignment
letter1.c:11:error: incompatible types in assignment
letter1.c:14:error: parse error before 'A'
letter1.c:14:error: parse error before 'A'
I don't know how to correct it.

edit: added [code] tags ~ jayman9
User is offlineProfile CardPM
+Quote Post

dragonlady
RE: Count Letter Problem
24 Oct, 2006 - 08:02 PM
Post #2

D.I.C Head
**

Joined: 7 Aug, 2005
Posts: 57


My Contributions
It looks like the problem originates with your declaration of letter[26][26]. So far you have an array of arrays, so the each element is an array of 26 elements. Then you have letter[i] = 0. This would be fine if letter[][] was a one-dimensional array, but here you are accessing an element of a two-dimensional array with one parameter. Think of it this way: if I had a two-d graph and I was trying to get a point on that graph, I'd have to supply an x and a y coordinate; anything else would be an error.

I'd use a nested loop on this one. For example, if I had a 2-d array of numbers, and I wanted to have the all first row elements store 1, the second row 2, etc...this is the kind of loop I'd use:
CODE

int numbers[3][3];

int num = 0;
for(i = 0; i < 3; i++)//i is a row counter
{
      num++;
      for(j = 0; j<3; j++){
          numbers[i][j] = num;  
          
      }
}

for(i = 0; i < 3; i++){
      for(j = 0; j<3; j++){
         cout<<numbers[i][j];
      }
      cout<<" ";
}

User is offlineProfile CardPM
+Quote Post

gregoryH
RE: Count Letter Problem
25 Oct, 2006 - 12:54 AM
Post #3

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
[quote name='Euniceno1' date='24 Oct, 2006 - 06:40 PM' post='178938']
The following are the code That I created:
CODE

#include <stdio.h>
#include <ctype.h>

int main(void)
{
   int c, i, j, letter[26][26];

   for (i=0; i<26; ++i) /* init array to zero */

   for( j= 0; j<26; ++j)
    
   while((c = getchar()) != EOF) /* count the letter */
        if(isupper© && islower©)

   for (i=0; i<26; ++i)
     if(i%6==0)
   for ( j= 0; j<26; ++j)
if(j%6==0) {
       printf("\n");
     printf("%4c%4c:%3d%3d", 'A' || 'a' +i +j, letter[i][j]);
   }
   printf("\n\n");
   return 0;
}

and the error I got from the gcc compiler:
letter1.c:In function 'main':
letter1.c:9:error: incompatible types in assignment
letter1.c:11:error: incompatible types in assignment
letter1.c:14:error: parse error before 'A'
letter1.c:14:error: parse error before 'A'
I don't know how to correct it.

edit: added
CODE
tags ~ jayman9
[/quote]
Euniceno

The compiler gave you line numbers....
[code]
File          which function
letter1.c : In function 'main':
                          the problem description.....
letter1.c:9:error: incompatible types in assignment
             ^ line number...


Lets get those lines down here...
CODE
#  Line
9  letter[i] = 0;
11 letter[j] = 0;
14 ++letter[c -> 'A' && c -> 'a'];


Now we can see a trend in the code.. Dragonlady has hit the nail on the head.

Letter[i] simply doesn't match the definition letter[][].
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:45AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month