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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
#include<iostream>
#include<fstream>
#include <cstring>
#include <string>
using namespace std;
struct Activity
{
char* title;
char* userid;
int duration;
float priority;
};
char* mystrtok(char* s, char d)
{
// Stores the state of string
static char* input = NULL;
// Initialize the input string
if (s != NULL)
input = s;
// Case for final token
if (input == NULL)
return NULL;
// Stores the extracted string
char* result = new char[strlen(input) + 1];
int i = 0;
// Start extracting string and
// store it in array
for (; input[i] != '\0'; i++) {
// If delimiter is not reached
// then add the current character
// to result[i]
if (input[i] != d)
result[i] = input[i];
// Else store the string formed
else {
result[i] = '\0';
input = input + i + 1;
return result;
}
}
// Case when loop ends
result[i] = '\0';
input = NULL;
// Return the resultant pointer
// to the string
return result;
}
int main()
{
Activity***** calendar;
calendar = new Activity ****[12];
Activity** singleActivity = new Activity* [5];
int acivityLength = 5;
for( int ai = 0; ai < acivityLength; ai++ ) {
Activity* row = new Activity[acivityLength-1];
singleActivity[ai] = row;
}
int totalmonthdays = 0;
for (int i = 0; i < 12; i++)
{
if (i == 0 || i == 2 || i == 4 || i == 6 || i == 7 || i == 9 || i == 11)
{
calendar[i] = new Activity ***[31];
totalmonthdays = 31;
}
else if (i == 3 || i == 5 || i == 8 || i == 10)
{
calendar[i] = new Activity ***[30];
totalmonthdays = 30;
}
else
{
calendar[i] = new Activity ***[28];
totalmonthdays = 28;
}
for (int j = 0; j < totalmonthdays; j++)
{
calendar[i][j] = new Activity **[24];
for (int k = 0; k < 24; k++)
{
calendar[i][j][k] = new Activity * [1];
calendar[i][j][k][0] = new Activity;
}
}
}
int c = 0, i = 0, linecount = 0, x = 0, coma_count = 0, id_count = 0, title_count = 0;
int useridx, activityaycount = 0;
int activitycount = 0;
int day = 0, month = 0, stime = 0, etime = 0;
double priority = 0.0;
int floatcount = 0;
char* userid;
char* useractivity;
char* titleStr;
ifstream ifile;
ofstream out_stream;
string line;
ifile.open("temp1.dat");
if (ifile.fail())
{
cout << "Input file opening failed";
exit(1);
}
else if (ifile.is_open())
{
while (getline (ifile,line))
{
if (line != "\0")
{
coma_count = 0;
char delim = ',';
char *arrayp;
arrayp = &line[0];
char *ptr = mystrtok(arrayp, delim);
int lineIndex = 1;
while(ptr != NULL)
{
if(lineIndex == 1)
{
char daybuff[2];
memcpy(daybuff, &ptr[0], 2);
daybuff[2] = '\0';
day = stoi(daybuff);
char monthbuff[2];
memcpy(monthbuff, &ptr[1],2);
if( monthbuff[0] == '/')
{
month = stoi(new char(monthbuff[1]));
}
else
{
monthbuff[2] = '\0';
month = stoi(monthbuff);
}
}
else if(lineIndex == 2)
{
char startbuff[2];
memcpy(startbuff, &ptr[0],2);
startbuff[2] = '\0';
stime = stoi(startbuff);
}
else if(lineIndex == 3)
{
char endbuff[2];
memcpy(endbuff, &ptr[0],2);
endbuff[2] = '\0';
etime = stoi(endbuff);
}
else if(lineIndex == 4)
{
userid = &ptr[0];
}
else if(lineIndex == 5)
{
useractivity = &ptr[0];
}
else if(lineIndex == 6)
{
titleStr = &ptr[0];
}
else if(lineIndex == 7)
{
char prbuff[6];
memcpy(prbuff, &ptr[0],6);
prbuff[6] = '\0';
priority = atof(prbuff);
}
//printf("'%s'\n", ptr);
ptr = mystrtok(NULL, delim);
lineIndex ++;
}
// day = parseDay(line);
int duration = etime - stime;
calendar[month - 1][day - 1][stime][0][0].priority = priority;
calendar[month - 1][day - 1][stime][0][0].duration = duration;
calendar[month - 1][day - 1][stime][0][0].userid = userid;
calendar[month - 1][day - 1][stime][0][0].title = titleStr;
cout << calendar[month - 1][day - 1][stime][0][0].title << endl;
coma_count = 0, c = 0, day = 0, month = 0, activityaycount = 0, activitycount = 0, priority = 0.0, floatcount = 0, duration = 0;
x++;
}
else
{
break;
}
}
ifile.close();
system("pause");
}
}
|