So basically i think i have the roots of this program down im getting an output.txt file but its not what im wanting here is the assignment.
Critical Path Analysis. A critical path analysis is a technique used to determine the time schedule for a project. This information is important in the planning stages before a project is begun, and it is also useful to evaluate the progress of a project that is partially completed. One method for this analysis starts by dividing a project into sequential events and then dividing each event into various tasks. Although one event must be completed before the next one is started, various tasks within an event can occur simultaneously. The time it takes to complete an event, therefore, depends on the number of days required to finish its longest task. Similarly, the total time it takes to finish a project is the sum of time it takes to finish each event.
Assume that the critical path information for a major construction project has been stored in a data file. Each line of the data file contains an event number, a task number, and the number of days required to complete the task. The data have been stored such that all the task data for the first event are followed by all the task data for the second event, and so on. A typical set of data is shown in the following table.
Event__Task___Number of Days
1______15_____3
1______27_____6
1______36_____4
2______15_____5
3______18_____4
3______26_____1
4______15_____2
4______26_____7
4______27_____7
5______16_____4
Write a program to read the critical path information from critical1.txt file and to print a project completion timetable into output1.txt.
Timetable lists each event number, number of tasks under this event, the maximum number of days for this event, and the total number of days for the project completion.
For example, your output1.txt will look like as follows based on the above input file:
Project completion timetable
---------------------------------------------------------------
Event____Num of tasks_____Max num.of days
------ ----------------- ----------------------
1__________3_________________6
2__________1_________________5
3__________2_________________4
4__________3_________________7
5__________1_________________4
---------------------------------------------------------------
Total number of days to finish the project: 26 days
My Output:
Project completion timetable
---------------------------------------------------
Event Num of tasks Max num.of days
------ ------------- ----------------------
---------------------------------------------------
Total number of days to finish the project: 0
As you can see it is not doing what its supposed to im guessing this is somthing wrong with my loops or i am not using fprintf right.
Please take a look at my code and give me some suggestions.
Thanks a lot
Code:
#include <stdio.h>
int main(void)
{
FILE *infp, *outfp;
int event, task, days, partevent, maxday, totday;
if ((infp = fopen("critical1.txt", "r"))==NULL)
{
printf("Input file cannot be opened\n");
return -1;
}
if ((outfp = fopen("output1.txt", "w"))==NULL)
{
printf("Output file cannot be opened\n");
return -1;
}
fprintf(outfp, "Project completion timetable\n");
fprintf(outfp, "---------------------------------------------------\n");
fprintf(outfp, "Event Num of tasks Max num.of days\n");
fprintf(outfp, " ------ ------------- ----------------------\n");
partevent=-1;
totday=0;
while(fscanf(infp, "%d %d %d",&event, &task, &days)==3)
{
if(partevent!=event)
{
if(partevent!=-1)
{
fprintf(outfp,"%d \t %d \t\t\t %d\n", partevent, task, maxday);
totday +=maxday;
}
task=1;
maxday=days;
partevent=event;
}
else
{
task++;
if(maxday<days)
{
maxday=days;
}
}
}
if(partevent!=-1)
{
fprintf(outfp,"%d \t %d \t\t\t %d\n", partevent, task, maxday);
totday +=maxday;
}
fprintf(outfp, "---------------------------------------------------\n");
fprintf(outfp,"Total number of days to finish the project: %d\n", totday);
fclose(infp);
fclose(outfp);
return 0;
}