hi again,
i want to write a program that reads text from a text file and pass the text to 2D array. and
text in the file is as follows (there is no order):
breaking benjamin lifehouse good charlotte bon jovi
nightwish within temptation
angels and airwaves
seether
below is the function which i do not know what i am doing and i feel lost. it should display the result each word each line and display the longest word together with the number of characters.
display should be like this
breaking
benjamin
lifehouse
....
thank you
Code:
void charCount(FILE *fp)
{
int wordArray[noOfWords][noOfChar];
int i, j = 0;
int nChar = 0;
int ch;
int longestWord = 0;
while ((ch = fgetc(fp)) != EOF)
{
if (ch == ' ')
{
i++;
}
wordArray[i][j] = ch;
j++;
}
printf("%s", wordArray[noOfWords][noOfChar]);
}