I have a section of the text file in the format below for an entire month for one patient.
January 1 Monday Brushing_teeth 9
January 1 Monday Washing_hands 5
January 1 Monday Twitching 6
January 1 Monday Lock_checking 40
January 2 Tuesday Brushing_teeth 10
January 2 Tuesday Eating_hair 10
January 2 Tuesday Twitching 10
January 3 Wednesday Brushing_teeth 5
January 3 Wednesday Grouping_food 3
January 4 Thursday Brushing_teeth 6
January 4 Thursday Washing_hands 10
January 4 Thursday Washing_Face 5
January 5 Friday Brushing_teeth 4
January 5 Friday Grouping_food 4
January 6 Saturday Brushing_teeth 7
I would like to be able to search through the file and for each activity the person does, add the amount of times it is done every time it occurs, and avg per week and per month
For eg. Brushing teeth 10
.....
.... brushing teeth 6
then total would be 16 etc etc.
#include <stdio.h>
#include <string.h>
int main()
{
int reps;
char comp[15][30]={"Brushing_teeth","Washing_Hands","Eating-Hair","Scratching","Biting_Nails","Cleaning_House","Changing_clothes","Twitching","Scrubbing_Floor","Skipping_last_step","Cracking_Knuckles","Grouping_Food","Washing_Face","Lock_Checking","Biting_Inside_Of_Mouth"};
char name[20];
char compulsions[40];
char month[10], day[20];
int date;
int i,j;
int total=0;
printf("Welcome to Track Me\n");
printf("Below is the list of all compulsions patients have done this month\n");
printf("%s\n %s\n %s\n %s\n %s \n%s \n%s",comp[0],comp[1],comp[2],comp[3],comp[4],comp[5],comp[6]);
printf("%s \n%s\n %s\n %s\n %s \n%s \n%s\n %s",comp[7],comp[8],comp[9],comp[10],comp[11],comp[12],comp[13],comp[14]);
printf("\n\n%s",comp[6]);
//to search for patient file
printf("Enter Patients Name to access file with extension .txt");
scanf("%s",name);
FILE *search;
search = fopen(name,"r");
if (search==NULL ){
printf("File could not be opened");
}
printf("Month Date Day Compulsion Repetitions\n");
while ( fscanf(search,"%s %d %s %s %d", month, &date, day, compulsions, &reps) > 4)
{
printf("%s %d %s %s %d\n",month, date, day, compulsions, reps);
if (compulsions==comp[0]){
reps+=reps;
}
}
printf("total amount of reps: %d\n", reps);
fclose(search);
}


Sign In
Create Account

Back to top









