We help IT Professionals succeed at work.

problem with 2D char array

shilpi84
shilpi84 asked
on
1,351 Views
Last Modified: 2008-01-09
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();
}
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2012
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
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'}
                   };
jkr
CERTIFIED EXPERT
Top Expert 2012
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
thanks jkr you  cleared my doubts

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.