Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C
how to do horizontal and vertical search for a word in a 2 dimensional character Array using c
Posted 28-Mar-13 1:50am
Comments
ThePhantomUpvoter at 28-Mar-13 7:01am
   
You would write some code in C.... do you have a question or problem with some of the code that you have written?
ayesha hassan at 28-Mar-13 7:40am
   
What have you tried so far? Do you have any piece of code that you tried? Please share that as well.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
 
Try it yourself, you may find it is not as difficult as you think!
 
But this isn't difficult - think about it as two problems: a "find it in the rows" and a "find it in the columns". Each needs a loop to check each row/column, and then it's just a "find the string in the one dimensional array" repeated.
 
Try it by hand, on paper, and see what you have to do. It's not difficult to work out! Laugh | :laugh:
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this Smile | :) and make changes accordingly!
 
char *arr[2][2] ;
    arr[0][0]="Apple";
    arr[0][1]="Book";
    arr[1][0]="Cat";
    arr[1][1]="Door";
    for(int i=0;i<=1;i++)
    {
        for(int j=0; j<=1 ; j++)
        {
            cout<<arr[i][j]<<endl;
        }
    }
    cout<<"\t\t\tSearching for character 'Cat'"<<endl;
    for(int i=0;i<=1;i++)
    {
        for(int j=0; j<=1 ; j++)
        {
            if(arr[i][j] == "Cat")
            {
                cout<<"\t\t\t*****Search Complete*****\nCharacter found at location ["<<i<<"]"<<"["<<j<<"]"<<endl;
            }
        }
    }
  Permalink  
Comments
nv3 at 28-Mar-13 8:14am
   
He didn't say 2-dim array of strings, but 2-dim array of characters. And btw. you string comparison will not work as you are comparing pointers and not strings. It might work accidentally if the compiler folds the two "Cats" strings and puts them in the same place. Otherwise, it's going to fail.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 515
1 Maciej Los 349
2 Richard MacCutchan 220
3 BillWoodruff 209
4 Mathew Soji 160
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100