You are on page 1of 4

#include <stdio.

h>
#include <string.h>
#include "student.c"
#pragma warning(disable: 4996)

int main(int argc, char *argv[])


{

if (argc > 0)
{
// Get name of file from command line argument
char inputFileName[124] = { 0 };
strcpy(inputFileName, (char*)argv - 1);

FILE* pstudent = NULL;


int i = 0;
int k = 0;
struct student what[10];
pstudent = fopen("Feedback.txt", "r");
char buffer[400] = { 0 };

if (pstudent != NULL)
{
while (fgets(buffer, 400, pstudent))
{

if (strstr(buffer, ","))
{
strcpy(what[i].name, buffer);
printf("%s", what[i].name);

}
else if (strstr(buffer, "Assignment"))
{
strcpy(what[i].feedback, (char*)buffer);
printf("%s", what[i].feedback);

else if (strstr((char*)buffer, "Marks"))


{
strcpy((char*)what[i].marks, (char*)buffer);
printf("%s", (char*)what[i].marks);

}
else if (strstr(buffer, "Comments"))
{
k = 0;
strcpy(what[i].comments[k], buffer);
printf("%s", what[i].comments[k]);
k = 1;
}
else if (strstr(buffer, "*") && strlen(buffer) > 3)
{
strcpy(what[i].comments[k], buffer);
printf("%s", what[i].comments[k]);
k++;
}
else if (strstr(buffer, "END"))
{
printf("\n");
i++;
}

}
else
{
printf("There is no file ");
}

for (i = 0; i < 3; i++)


{
FILE *pnew = NULL;
char x[100] = { 0 };
strcpy(x, what[i].name);
strtok(x, "\n");
strcat(x, ".txt");

// concatenate the name of the subdirectory onto the beginning of the file name
if ((pnew = fopen(strcat("Individual\\", x), "w")) != NULL)
{
// subdirectory exists, so continue with logic
}
else
{
// doesn't exist, try to create if it doesnt create then throw error

// first, check if the subdirectory exists, if it does, then use it


// if it doesn't, then create it - if creation fails log error and quit program

fprintf(pnew, "%s", (char*)what[i].name);


fprintf(pnew, "%s", (char*)what[i].feedback);
fprintf(pnew, "%s", (char*)what[i].marks);
fprintf(pnew, "%s", (char*)what[i].comments);

int j = 1;
while (j<4)
{
fprintf(pnew, "\t%s", what[i].comments[j]);
j++;
}

fclose(pnew);
}

if (pstudent != NULL)
fclose(pstudent);

}
else
{
printf("No command line args specified");
}

return 0;
}

You might also like