int main(int argc, char* argv[]){ //Define an array of two customers Customer myCustomers[2]; int customerSize = sizeof(myCustomers)/sizeof(myCustomers[0]); char findName[30]; //Get the data from the user(keyboard) for(int i = 0; i < customerSize; i++){ printf("Enter the name of Customer #%d\n", i+1); scanf("%s", myCustomers[i].name); printf("Enter the phone of Customer #%d\n", i+1); scanf("%s", myCustomers[i].phone); printf("Enter the age of Customer #%d\n", i+1); scanf("%d", &myCustomers[i].age); //getchar(); //Use getchar } printCustomer(myCustomers, customerSize); //Get name from user input //Pass it to searchStudent function and return number or -1. printf("Who are you looking for?\n"); printf("Enter a name to be searched \n"); scanf("%s", findName); //Call the search int elementNum = -1; elementNum = searchStudent(findName, myCustomers, customerSize); if (elementNum != -1){ printf("Found %s at element %d", myCustomers[elementNum].name, elementNum); } else { printf("Not found"); } }//int main
void main() { Node* list = 0; Node* secondList = 0; Student* stud = 0; FILE *f; f = fopen("Students.csv", "r"); if (f) { stud = (Student*)malloc(sizeof(Student)); // buffers char name[256]; char birth[256]; char faculty[256]; // pattern: 1,John Smith,10-10-1990,Faculty of Computer Sciene,1,1008 fscanf(f, "%d, %[^,], %[^,], %[^,], %hd, %hd", &(stud->id), name, birth, faculty, &stud->year, &stud->group); while (!feof(f)) { stud->name = (char*)malloc((strlen(name) + 1) * sizeof(char)); strcpy(stud->name, name); char* token; // solving date field char separator[2] = "-"; token = strtok(birth, separator); stud->birthDay.day = atoi(token); token = strtok(0, separator); stud->birthDay.month = atoi(token); token = strtok(0, separator); stud->birthDay.year = atoi(token); // solving name field stud->name = (char*)malloc((strlen(name) + 1) * sizeof(char)); strcpy(stud->name, name); // solving faculty stud->faculty = (char*)malloc((strlen(faculty) + 1) * sizeof(char)); strcpy(stud->faculty, faculty); // INSERTION HERE: //list = frontInsertion(list, stud); list = rearInsertion(list, stud); secondList = frontInsertion(secondList, stud); // allocate new student && read next line from csv file stud = (Student*)malloc(sizeof(Student)); fscanf(f, "%d, %[^,], %[^,], %[^,], %hd, %hd", &(stud->id), &name, &birth, &faculty, &stud->year, &stud->group); } } else { perror("[FILE ERROR]"); } printList(list); searchStudent(list, "fate1"); searchStudent(list, "fate2"); searchStudent(list, "fate3"); list = deleteStudent(list, "Max", 1); //list = deleteElement(list, "Philip Rafaello"); printf("\nList after deletion of Max: "); printList(list); // search for a student in list Student* searched = searchElement(list, "John Smith"); if (searched) { printf("\nStudent found: %s", searched->name); } else { printf("\nStudent not found!"); } // interchange adjacent nodes in list list = interchangeNodesAdj(list, 3, 4); printf("\nList after adjacent interchange: "); printList(list); // interchange nodes in list list = interchangeNodes(list, 1, 5); printf("\nList after adjacent interchange: "); printList(list); // sort list by year printf("\nSorting the list: "); sortList(&list); printList(list); // list concatenation printf("\nFirst list: "); printList(list); printf("\nSecond list: "); printList(secondList); //Node* concatenatedList = concatenateList(list, secondList); //printf("\nResult: "); //printList(concatenatedList); deleteList(list); // testing some things int a = 0x5; a = 0xA; a = 0xB; a = 0xC; printf("\nHex: %x", a); // finally fclose(f); printf("\n"); }