2 dimension arrays

This is a discussion on 2 dimension arrays within the C++ Programming forums, part of the General Programming Boards category; How is a character e.g, 'ch' in a two-dimensional array found? for instance: how will you find a chararcter ch ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    11

    2 dimension arrays

    How is a character e.g, 'ch' in a two-dimensional array found?


    for instance: how will you find a chararcter ch ( also the position 'where' it is found)? afile is a pre-opened file.

    int findC(char ch, fstream & afile, int & where)

    int position=1
    char c

  2. #2
    Registered User Engineer's Avatar
    Join Date
    Oct 2001
    Posts
    125
    Sounds like homework. Here is a couple of suggestions:

    If you want to find a char inside a two dimensional array, you will have to scan the array element by element using, for instance, nested for loops. When you find the char you can save its location in two integers (for the two dimensions of the array).

    If you want to find a char inside an open file, you will have to scan the file char by char, keeping a counter and comparing what you got from the file, and when you got a match saving the counter into a single integer.

    Cheers.
    1 rule of the Samurai Code: if you have nothing to say, don't say anything at all!

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    11
    thanx for your help, but can u please give some examples because your answer is still not quite clear to me.
    thanx.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 03:24 PM
  2. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 09:47 PM
  4. a Problem about two dimension arrays and Fibonacci
    By louis_mine in forum C Programming
    Replies: 2
    Last Post: 10-16-2004, 11:33 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 08:24 PM

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