Link to home
Start Free TrialLog in
Avatar of shilpi84
shilpi84

asked on

problem with 2D char array

Please tell me what's wrong with the initialization of this 2D char array a[10][2];
I've tried with curly brackets too, but nothing happends. With round brackets, ASCII values get stored;

#include<iostream>
#include<conio.h>
#include<string.h>

using namespace std;

class loj
{
     
              char a[10][2];
              string s;
              char b[2];
              int j;
             
      public:
             void input();
             void logic();
             loj();
};
loj::loj()
{
          a[10][2]=(
                    ('n','o'),
                    ('p','a'),
                    ('r','e'),
                    ('c','i'),
                    ('v','o'),
                    ('m','u'),
                    ('x','a'),
                    ('z','e'),
                    ('b','i'),
                    ('s','o')
                   );
                   //to test the value of a[10][2];
          for(int i=0;i<2;i++)
                  for(int j=0;i<10;j++)
                          cout<<a[i][j];
          j=0;
}
void loj::input()
{
     cout<<"enter a lojo string\n";
     cin>>s;
     cout<<"sd";

}
void loj::logic()
{
     cout<<s;
     for(int i=0;i<s.length();i++)
     {
          while(j<=1)
          {
                     
                      b[j]=s[i];
                      j++;
          }
          if(j==2){
                   
                      for(int k=0;k<=9;k++)
                      {
                              if((b[0]==a[0][k])&&(b[1]==a[0][k]))
                              {
                                                                  cout<<i<<"\t";
                              }
                      }
                      j=0;
            }
     }
}
     
int main()
{
    loj l;
    l.input();
    l.logic();
    getche();
}
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shilpi84
shilpi84

ASKER

thanks jkr... it works now... but why couldn't this work directly without using b and then copying

a[10][2]={
                    {'n','o'},
                    {'p','a'},
                    {'r','e'},
                    {'c','i'},
                    {'v','o'},
                    {'m','u'},
                    {'x','a'},
                    {'z','e'},
                    {'b','i'},
                    {'s','o'}
                   };
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks jkr you  cleared my doubts