Hi there!
I would like to stream datas from file and store it into structures to work with it later.
The datas look like this.
The first line contains the number of "text messages" in the file.
next line: hour, minute, phone number
next line: the text of the message.
repeat
like this:
30
9 11 123456789
Hi, When are you coming home?
9 13 434324223
I would like to eat pizza!
9 14 434324223
Where can I pick you up?
...
...
My code looks like this so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
#include <fstream>
using namespace std;
// struct to store info on each sms
struct oneSms
{
int hour;
int minute;
int number;
char text [100];
};
//array for all the sms I want to store
typedef oneSms moreSms [100];
//function to stream the data from file
void input (moreSms &sms, int &count);
int main()
{
int count = 0;
moreSms sms;
input (sms, count);
return 0;
}
void input (moreSms &sms, int &count)
{
ifstream file;
file.open("sms.txt");
int i = 0;
if (file.is_open())
{
file >> count;
while (file.good())
{
file >> sms[i].hour >> sms[i].minute >> sms[i].number;
file.getline(sms[i].text, 100);
i++;
}
}
file.close();
}
|
Any ideas what am I doing wrong, or how coud I do it better?
Why doesnt 'i' get a higher value than 1?
Thank you