hi HPexpress
HPexpress wrote: |
---|
1 2 3 4 5 6
|
fin.get(ch);
while (ch != '\n')
{
fin.get(ch);
|
|
there are two calls to read the character from the stream. you should have missed the first character.
and as for looping it into the array, here's the logic. i'm using C, so i don't really know C++ syntax.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
for (row=0; row<5; row++)
{
for (col=0; col<5; col++)
{
//read the character from stream
//check if character is valid
if (...) //if invalid, take necessary action here
{
...
}
else //if valid, store it
{
//store character into array[row][col]
}
}
}
|
there are lots of loopholes in the part where we read character from stream. we need to check for the validity in case, say, the stream has ended, etc.
to remove the repeats, you can either do it after the array has been filled or otherwise. either way, it works.
its best to perform the removal of recurring characters before the array creation. you can use the same loop above, and do a check with the existing array. compare between the character in stream and the array. if found, then do not store, and continue the loop.
hope this helps.