| AndyC (1) | |||
|
Hi, I am new to the site and and finding it a great source of information.I would be very grateful if someone could help me with a small problem. I am trying to write a simple program that will read text file containing two columns. The first columns contains individual words in the (Catalan) language, the second column contains the English meaning of the word. I am trying to create a simple program that can randomly choose a word from my growing list of Catalan words, and ask me what the meaning of the word is. If I guess correctly it chooses another and so on.My plan is to make it do this at random intervals through the day while I am working at my computer. The problem is, although I have been writing algorithms for mathematical applications in C++, I have no experience of working with text, characters or strings. The text file would be as follows word1 meaning1 word2 meaning2 word3 meaning3 I cannot get the coded to read the words into an array eg. char myarray[4][2]; Ideally I would like to read in the whole text file (which will grow as my vocabulary increases, so the size will file will increase. The code, I have been trying to use is as follows (borrowed from advice in this forum). This is my first attempt, it does not manage to read in the words and is very rustic I am sure. Perhaps someone could advise me if there is a better approach. I am sure learning to do this will help my research work also. Just any answers to my immeadiate problem would be fine. Any futher advice on how to approach the wider aim is also welcome. Many thanks
| |||
|
|
|||
| Mitsakos (343) | |||
This program reads the two columns from the file into the data_array. It is better to use a string type array because you dont have to worry about the size of the reading. If you use char array then you need 3 dimensional to handle: 1. The line number, 2.The Row, 3.The length of the chars... Also at your program at line 27 the if statement you have is always gonna be true because ++col is always gonna be 1. I you want to check if it is 1 and then add one you should use col++ == 1. | |||
|
|
|||
| salman (9) | |||||
I tried it out and the way I did it is open file
then use a do while loop to get the word and meaning. Using
this should get each word in word[i] and each meaning into a variable meaning[i] | |||||
|
Last edited on
|
|||||