Hello.
Would anyone please give me a hint how to solve my problem?
I'm reading a file into a char array.
On the first line in the text file there are two numbers which
specify the size of the array, ie "20 20".
Starting on the next line is the array of characters
(characters are arranged in a 20x20 grid with white spaces
between them)
First, I'm using fscanf in a 'for' loop to read the numbers and make a note of them. I'm using them to create a char array of that size for holding the letters.
Next I read in the grid of letters, like so
1 2 3 4 5 6 7 8 9 10 11 12
|
i=0;
j=0;
while((ch=fgetc(fp))!=EOF){
if(isalpha(ch)){
array[i][j]=ch;
j++;
if(j==width of the array){
i++;
j=0;
}
}
}
|
As you can see, this code reads the whole file from the beginning
and ignores those two numbers that are on the first line of the file.
All is good but... I also need to make sure that there aren't any
stray numbers that might have found it's way into the grid of letters.
And if there is, I should warn the user and abort.
The way my code is right now, any numbers will be simply ignored.
But I need to be able to differentiate between the two numbers
at the beginning of the file and those that might happen to be in the
grid of letters(a typo,for example).
Any thoughts?
Thank you.