0

Hi everybody!

I must make program in c++ that reads unknown number of words from a text file to char arr which after that i will have to sort the words by the first letter by alphabet in a stack.
can any body help me please?

txt file:
den rock sky apple cycle fruit van sun

i know how to read file with

sting line;
ifstream in("file.txt", ios::out);
getline(in,line);
in.close ();

but I have to learn to program in the lower level - char arr's not by using string that are just linked char arr's

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Borkoff
0

Here is something to get you started :

int main(){
 const int MAX_WORD_ALLOWED= 1000; //1000 words allowed
 const int MAX_WORD_LENGTH = 256; //words length cannot exceed this amount

 char listOfWords[MAX_WORD_ALLOWED][MAX_WORD_LENGTH] = {};

 ifstream fileInput("test.txt");
 unsigned wordNumber = 0;
 
 while(fileInput.get(listOfWords[wordNumber++],MAX_WORD_LENGTH) && wordNumber < MAX_WORD_ALLOWED ){
   //blah blah blah
 }
}

Its not tested, but you should get the idea.

Edited by firstPerson: n/a

0

nope.. i know this is a two-dimensial array but this does not fit because I must be able to read unlimited number words to a char arr list.

i found somewhere that fscanf could be useful, but I do not understand the parameters.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.