Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CommandLineAssignment1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "stdlib.h"
- #include "stdio.h"
- #include "string.h"
- #include "ctype.h"
- FILE *commandPointer;
- struct Date
- {
- int day;
- int month;
- int year;
- };
- struct Time
- {
- int startHour;
- int startMinute;
- int endHour;
- int endMinute;
- };
- struct workTime
- {
- int employeeID;
- struct Date date;
- struct Time startTime;
- struct Time endTime;
- };
- struct workTime employee[20];
- int main(int argc, char *commandArgument[])
- {
- int i = 2;
- int j = 0;
- char delimiter1[2] = "/";
- char delimiter2[2] = ":";
- char *commandToken;
- printf("%s\n", commandArgument[0]);
- printf("%s\n", commandArgument[1]);
- commandPointer = fopen("C:\\Users\\CraigBreathnach\\Desktop\\workLog.txt", "a+");
- // Section 1
- while (commandArgument != NULL)
- {
- if (!strcmp("/a", commandArgument[i]))
- {
- employee[j].employeeID = atoi(commandArgument[i++]);
- printf("Employee I.D. : %d\n", employee[j].employeeID);
- }
- i++;
- if ((commandToken = strtok(commandArgument[i], delimiter1)) != NULL)
- {
- employee[j].date.day = atoi(commandToken);
- printf("Day : %d\n", employee[j].date.day);
- }
- if ((commandToken = strtok(NULL, delimiter1)) != NULL)
- {
- employee[j].date.month = atoi(commandToken);
- printf("Month : %d\n", employee[j].date.month);
- }
- if ((commandToken = strtok(NULL, delimiter1)) != NULL)
- {
- employee[j].date.year = atoi(commandToken);
- printf("Year : %d\n", employee[j].date.year);
- }
- i++;
- if ((commandToken = strtok(commandArgument[i], delimiter2)) != NULL)
- {
- employee[j].startTime.startHour = atoi(commandToken);
- printf("Start Time (Hour) : %d\n", employee[j].startTime.startHour);
- }
- if ((commandToken = strtok(NULL, delimiter2)) != NULL)
- {
- employee[j].startTime.startMinute = atoi(commandToken);
- printf("Start Time (Minute) : %d\n", employee[j].startTime.startMinute);
- }
- if ((commandToken = strtok(commandArgument[6], delimiter2)) != NULL)
- {
- employee[j].endTime.endHour = atoi(commandToken);
- printf("End Time (Hour) : %d\n", employee[j].endTime.endHour);
- }
- if ((commandToken = strtok(NULL, delimiter2)) != NULL)
- {
- employee[j].endTime.endMinute = atoi(commandToken);
- printf("End Time (Minute) : %d\n", employee[j].endTime.endMinute);
- }
- j++;
- }
- //if (!strcmp("/a", commandArgument[2]))
- //{
- // employee[i].employeeID = atoi(commandArgument[3]);
- // printf("Employee I.D. : %d\n", employee[i].employeeID);
- // i++;
- //}
- //if ((commandToken = strtok(commandArgument[4], delimiter1)) != NULL)
- //{
- // employee[i].date.day = atoi(commandToken);
- // printf("Day : %d\n", employee[i].date.day);
- // i++;
- //}
- //if ((commandToken = strtok(NULL, delimiter1)) != NULL)
- //{
- // employee[i].date.month = atoi(commandToken);
- // printf("Month : %d\n", employee[i].date.month);
- // i++;
- //}
- //if ((commandToken = strtok(NULL, delimiter1)) != NULL)
- //{
- // employee[i].date.year = atoi(commandToken);
- // printf("Year : %d\n", employee[i].date.year);
- // i++;
- //}
- //if ((commandToken = strtok(commandArgument[5], delimiter2)) != NULL)
- //{
- // employee[i].startTime.startHour = atoi(commandToken);
- // printf("Start Time (Hour) : %d\n", employee[i].startTime.startHour);
- // i++;
- //}
- //if ((commandToken = strtok(NULL, delimiter2)) != NULL)
- //{
- // employee[i].startTime.startMinute = atoi(commandToken);
- // printf("Start Time (Minute) : %d\n", employee[i].startTime.startMinute);
- // i++;
- //}
- //if ((commandToken = strtok(commandArgument[6], delimiter2)) != NULL)
- //{
- // employee[i].endTime.endHour = atoi(commandToken);
- // printf("End Time (Hour) : %d\n", employee[i].endTime.endHour);
- // i++;
- //}
- //if ((commandToken = strtok(NULL, delimiter2)) != NULL)
- //{
- // employee[i].endTime.endMinute = atoi(commandToken);
- // printf("End Time (Minute) : %d\n", employee[i].endTime.endMinute);
- // i++;
- //}
- //// Section 2
- //if (!strcmp("1010", commandArgument[7]))
- //{
- // employee[i].employeeID = atoi(commandArgument[7]);
- // printf("Employee I.D. : %d\n", employee[i].employeeID);
- // i++;
- //}
- //if ((commandToken = strtok(commandArgument[8], delimiter1)) != NULL)
- //{
- // employee[i].date.day = atoi(commandToken);
- // printf("Day : %d\n", employee[i].date.day);
- // i++;
- //}
- //if ((commandToken = strtok(NULL, delimiter1)) != NULL)
- //{
- // employee[i].date.month = atoi(commandToken);
- // printf("Month : %d\n", employee[i].date.month);
- // i++;
- //}
- //if ((commandToken = strtok(NULL, delimiter1)) != NULL)
- //{
- // employee[i].date.year = atoi(commandToken);
- // printf("Year : %d\n", employee[i].date.year);
- // i++;
- //}
- //if ((commandToken = strtok(commandArgument[9], delimiter2)) != NULL)
- //{
- // employee[i].startTime.startHour = atoi(commandToken);
- // printf("Start Time (Hour) : %d\n", employee[i].startTime.startHour);
- // i++;
- //}
- //if ((commandToken = strtok(NULL, delimiter2)) != NULL)
- //{
- // employee[i].startTime.startMinute = atoi(commandToken);
- // printf("Start Time (Minute) : %d\n", employee[i].startTime.startMinute);
- // i++;
- //}
- //if ((commandToken = strtok(commandArgument[10], delimiter2)) != NULL)
- //{
- // employee[i].endTime.endHour = atoi(commandToken);
- // printf("End Time (Hour) : %d\n", employee[i].endTime.endHour);
- // i++;
- //}
- //if ((commandToken = strtok(NULL, delimiter2)) != NULL)
- //{
- // employee[i].endTime.endMinute = atoi(commandToken);
- // printf("End Time (Minute) : %d\n", employee[i].endTime.endMinute);
- // i++;
- //}
- //// Section 3
- //if (!strcmp("2987", commandArgument[11]))
- //{
- // employee[i].employeeID = atoi(commandArgument[11]);
- // printf("Employee I.D. : %d\n", employee[i].employeeID);
- // i++;
- //}
- //if ((commandToken = strtok(commandArgument[12], delimiter1)) != NULL)
- //{
- // employee[i].date.day = atoi(commandToken);
- // printf("Day : %d\n", employee[i].date.day);
- // i++;
- //}
- //if ((commandToken = strtok(NULL, delimiter1)) != NULL)
- //{
- // employee[i].date.month = atoi(commandToken);
- // printf("Month : %d\n", employee[i].date.month);
- // i++;
- //}
- //if ((commandToken = strtok(NULL, delimiter1)) != NULL)
- //{
- // employee[i].date.year = atoi(commandToken);
- // printf("Year : %d\n", employee[i].date.year);
- // i++;
- //}
- //if ((commandToken = strtok(commandArgument[13], delimiter2)) != NULL)
- //{
- // employee[i].startTime.startHour = atoi(commandToken);
- // printf("Start Time (Hour) : %d\n", employee[i].startTime.startHour);
- // i++;
- //}
- //if ((commandToken = strtok(NULL, delimiter2)) != NULL)
- //{
- // employee[i].startTime.startMinute = atoi(commandToken);
- // printf("Start Time (Minute) : %d\n", employee[i].startTime.startMinute);
- // i++;
- //}
- //if ((commandToken = strtok(commandArgument[14], delimiter2)) != NULL)
- //{
- // employee[i].endTime.endHour = atoi(commandToken);
- // printf("End Time (Hour) : %d\n", employee[i].endTime.endHour);
- // i++;
- //}
- //if ((commandToken = strtok(NULL, delimiter2)) != NULL)
- //{
- // employee[i].endTime.endMinute = atoi(commandToken);
- // printf("End Time (Minute) : %d\n", employee[i].endTime.endMinute);
- // i++;
- //}
- commandPointer = fopen("C:\\Users\\CraigBreathnach\\Desktop\\workLog.txt", "a+");
- //fputs(commandArgument[2], commandPointer);
- //itoa(1, employee[0].employeeID, 10)
- char commandHolder[30];
- sprintf(commandHolder, "%d", employee[0].employeeID);
- fputs(commandHolder, commandPointer);
- return 0;
- }
- /*
- Do not include .exe in command line argument.
- Mode a+ for ammending file.
- /p prints from the file, not the data structure.
- Put search term after /s in command line argument.
- Type chekcing not available with macros-how to solve?
- .h files need a \n at the end so they don't concatenate to each other.
- enum = Enumerator variable, special type of integer that creates a relationship between the variables within it and numbers (first variable is zero, second 1, etc).
- Can refer to variables via enum name instead of just its number.
- STATEs = enum name used to check current state of the system. Can call a function to return values, whatever stated in STATES.
- Names can be anything, just like variables.
- Let first element = 1, the rest will adjust appropriately.
- Try not to mess with default values of the enums; if you have to, use known values instead.
- #include "stdafx.h"
- #include "stdlib.h"
- #include "stdio.h"
- #include "string.h"
- #include "ctype.h"
- #include "math.h"
- #include "time.h"
- FILE * allocationPointer;
- typedef struct contact
- {
- char *UserName;
- char *firstName;
- char *surname;
- char *displayName;
- char *jobTitle;
- char *department;
- char *officeNumber;
- char *officePhone;
- char *mobilePhone;
- char *fax;
- char *address;
- char *city;
- char *state;
- char *zip;
- char *country;
- };
- void OpenFile();
- void PrintContact(contact *theContact);
- void CloseFile();
- int l = 1;
- int main()
- {
- OpenFile();
- printf("\n");
- return 0;
- }
- void OpenFile()
- {
- int n = 5;
- int i = 0;
- allocationPointer = fopen("C:\\Users\\CraigBreathnach\\Desktop\\GY350 College\\CT103 Computer Programming\\Semester 2\\Week 6\\DynamicAllocationFile1.txt", "r");
- if (allocationPointer == NULL)
- {
- printf("Error! The file was not read correctly. Please check that the file path is correct.\n\n");
- }
- else
- {
- printf("Success! The file was read correctly. The file path is correct.\n\n");
- }
- char line[201];
- for (int i = 0; i <= 1; i++)
- {
- fgets(line, 176, allocationPointer);
- }
- char delimiter[2] = ",";
- char *token;
- int j = 0;
- int string = 0;
- while(!feof(allocationPointer))
- {
- contact *employeeData[1000];
- employeeData[j] = (contact *)malloc(sizeof(contact));
- fgets(line, 201, allocationPointer);
- if ((token = (strtok(line, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->UserName = (char *)malloc(string);
- strcpy(employeeData[j]->UserName, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->firstName = (char *)malloc(string);
- strcpy(employeeData[j]->firstName, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->surname = (char *)malloc(string);
- strcpy(employeeData[j]->surname, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->displayName = (char *)malloc(string);
- strcpy(employeeData[j]->displayName, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->jobTitle = (char *)malloc(string);
- strcpy(employeeData[j]->jobTitle, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->department = (char *)malloc(string);
- strcpy(employeeData[j]->department, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->officeNumber = (char *)malloc(string);
- strcpy(employeeData[j]->officeNumber, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->officePhone = (char *)malloc(string);
- strcpy(employeeData[j]->officePhone, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->mobilePhone = (char *)malloc(string);
- strcpy(employeeData[j]->mobilePhone, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->fax = (char *)malloc(string);
- strcpy(employeeData[j]->fax, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->address = (char *)malloc(string);
- strcpy(employeeData[j]->address, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->city = (char *)malloc(string);
- strcpy(employeeData[j]->city, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->state = (char *)malloc(string);
- strcpy(employeeData[j]->state, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->zip = (char *)malloc(string);
- strcpy(employeeData[j]->zip, token);
- }
- if ((token = (strtok(NULL, delimiter))) != NULL)
- {
- string = sizeof(char)*strlen(token) + 1;
- employeeData[j]->country = (char *)malloc(string);
- strcpy(employeeData[j]->country, token);
- }
- PrintContact(employeeData[j]);
- j++;
- }
- CloseFile();
- }
- void CloseFile()
- {
- fclose(allocationPointer);
- }
- void PrintContact(contact *theContact)
- {
- printf("User Name %d : %s\nFirst Name %d : %s\nSurname %d : %s\nDisplay Name %d : %s\nJob Title %d : %s\nDepartment %d : %s\nOffice Number %d : %s\nOffice Phone %d : %s\nMobile Phone %d : %s\nFax %d : %s\nAddress %d : %s\nCity %d : %s\nState %d : %s\nZip %d : %s\nCountry %d : %s\n",
- l, theContact->UserName, l, theContact->firstName, l, theContact->surname, l, theContact->displayName, l, theContact->jobTitle, l, theContact->department, l, theContact->officeNumber, l, theContact->officePhone,
- l, theContact->mobilePhone, l, theContact->fax, l, theContact->address, l, theContact->city, l, theContact->state, l, theContact->zip, l, theContact->country);
- l++;
- }
- #include "stdafx.h"
- #include "stdio.h"
- #include "stdlib.h"
- #include "string.h"
- #include "ctype.h"
- FILE *linkedPointer;
- struct result
- {
- char last[40];
- char first[40];
- int age;
- char email[40];
- struct result *next;
- };
- result * generateLinkedList();
- void searchLinkedList(result * list, int age);
- int main()
- {
- int searchTerm = 0;
- int searchOptions = 1;
- result * linkedList = NULL;
- linkedList = generateLinkedList();
- while (searchOptions != 0)
- {
- printf("Please enter a number to search for records based on a person's age. Enter 0 to end the program. \n");
- scanf("%d", &searchTerm);
- if (searchTerm == 0)
- {
- printf("You chose option 0. The program will now end. \n");
- searchOptions = 0;
- exit(0);
- }
- else
- {
- searchLinkedList(linkedList, searchTerm);
- }
- }
- return 0;
- }
- result * generateLinkedList()
- {
- int i = 0;
- result * startNode = NULL;
- result * tempNode = NULL;
- result * currentNode = NULL;
- char linkedLines[100];
- char delim[2] = ",";
- char *linkedToken;
- int tempToken = 0;
- linkedPointer = fopen("C:\\Users\\CraigBreathnach\\Desktop\\GY350 College\\CT103 Computer Programming\\Semester 2\\Week 7\\LinkedListFile1.txt", "r");
- if (linkedPointer == NULL)
- {
- printf("Error! The file was not found. Please ensure the file path is correct. \n\n");
- }
- else
- {
- printf("Success! The file was found. The file path is correct. \n");
- fgets(linkedLines, 200, linkedPointer);
- while (!feof(linkedPointer))
- {
- tempNode = (result*)malloc(sizeof(result));
- fgets(linkedLines, 200, linkedPointer);
- linkedToken = strtok(linkedLines, delim);
- {
- if (linkedToken != NULL)
- {
- strcpy(tempNode->last, linkedToken);
- }
- }
- linkedToken = strtok(NULL, delim);
- {
- if (linkedToken != NULL)
- {
- strcpy(tempNode->first, linkedToken);
- }
- }
- linkedToken = strtok(NULL, delim);
- {
- if (linkedToken != NULL)
- {
- tempToken = atoi(linkedToken);
- tempNode->age = tempToken;
- }
- }
- linkedToken = strtok(NULL, delim);
- {
- if (linkedToken != NULL)
- {
- strcpy(tempNode->email, linkedToken);
- }
- }
- tempNode->next = NULL;
- if (startNode == NULL)
- {
- startNode = tempNode;
- }
- else
- {
- currentNode = startNode;
- while (currentNode->next != NULL)
- {
- currentNode = currentNode->next;
- }
- currentNode->next = tempNode;
- }
- }
- }
- return startNode;
- }
- void searchLinkedList(result * startNode, int age)
- {
- result * currentNode = startNode;
- while (currentNode != NULL)
- {
- if (age == currentNode->age)
- {
- printf("%s %s\n", currentNode->first, currentNode->last);
- }
- currentNode = currentNode->next;
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement