//Ask user for input, adds data to list or updates //existing data. void buyStock() { char symbol[50] = "NULL";//Store symbol char name[50] = "NULL";//Store name double price;//Store purchase price int amount;//Store stock purchase amount int found = 0;//Tracks if data already in list printf("\n\n"); while(fgetc(stdin)!='\n'); printf("Enter the company symbol:"); fgets(symbol,50,stdin); printf("Enter the company name:"); fgets(name,50,stdin); printf("Enter Price:"); scanf("%lf",&price); printf("Enter amount you wish to purchase:"); scanf("%d",&amount); int i; for(i=0;i<strlen(name);i++) { if(name[i] == '\n') { name[i] = '\0';//Strip new line } } for(i=0;i<strlen(symbol);i++) { if(symbol[i] == '\n') { symbol[i] = '\0';//Strip new line } } if(found == 0)//Data not already in list { Stock d; char * n = (char*)calloc(50,sizeof(char)); char * s = (char*)calloc(50,sizeof(char)); strcpy(n,name); strcpy(s,symbol); d.price = price; d.shares = amount; d.c.name = n; d.c.symbol = s; addOrdered(d);//Add to list } }
void parseAliasCMD(Node ** head, char * string){ char tempS[1000]; char * aliasTemp = NULL; char ** aliasArgs = NULL; char * CMDTemp = NULL; #if TESTER printf("input string %s<---\n", string); #endif strcpy(tempS,string); aliasTemp = strtok(tempS , "="); CMDTemp = strtok(NULL, "="); strip(CMDTemp); //clear out any " or ' characters for(int i = 0; i < strlen(CMDTemp); i++){ if( *(CMDTemp + i) == '\'' || *(CMDTemp + i) == '\"'){ *(CMDTemp + i) = ' '; } } #if TESTER printf("---->DEBUG:alias temp =%s<-------\n", aliasTemp); #endif //We want to remove the alias word makeargs(aliasTemp, &aliasArgs); //copy back the alias word strcpy(aliasTemp, aliasArgs[1]); //clean the memory a bit clean(2, aliasArgs); #if TESTER printf("---->DEBUG:alias temp =%s<-------\n", aliasTemp); #endif #if TESTER printf("---->DEBUG:cmd temp =%s<-------\n", CMDTemp); #endif addOrdered(head, aliasTemp, CMDTemp); }
Node * readPlayers(char ** inFileNames) { int fileCount = 0; int playerCount = 0; char temp[MAX]; FILE * fin = NULL, * finTeams = NULL; Node * head = NULL; finTeams = fopen("NFL2010Teams.csv", "r"); while(inFileNames[fileCount] != NULL) { char * myStringCopy = NULL; char ** playerInput = (char**) calloc(4, sizeof(char*));//changed to char* Player * newPlayer = NULL; char * position = NULL; stripRN(inFileNames[fileCount]); fin = openKnownFile(inFileNames[fileCount], "r"); position = getPosition(inFileNames[fileCount]); fgets(temp, MAX, fin); fgets(temp, MAX, fin); while(fgets(temp, MAX, fin)!= NULL) { myStringCopy = (char *)calloc(strlen(temp)+1, sizeof(char)); //changed to char strcpy(myStringCopy,temp); char * toke = strtok(myStringCopy, " "); playerInput[playerCount] = (char*) calloc(strlen(toke)+1,sizeof(char)); strcpy(playerInput[playerCount], toke); while(playerCount < 3) { playerCount++; toke = strtok(NULL, ","); playerInput[playerCount] = (char*) calloc(strlen(toke)+1,sizeof(char)); strcpy(playerInput[playerCount],toke); } newPlayer = createPlayer(playerInput[0], playerInput[1],playerInput[2], atoi(playerInput[3]), position); addOrdered(newPlayer, &head); while(playerCount > -1) { free(playerInput[playerCount]); playerCount--; } playerCount++; free(myStringCopy); } free(playerInput); free(position); fclose(fin); fileCount++; } changeTeamName(&head, finTeams); fclose(finTeams); return(head); }
int main() { Node * head = NULL; FILE * fin = NULL; fin = openFile(); createWordNodes(fin,&head); printf("\n\n-----------Printing Original List-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); char temp[6] = "frank"; Word * tempWord = createWordStruct(temp); addOrdered(tempWord, &head); printf("\n\n-----------Printing List Adding Ordered the name \"frank\"-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); char temp1[6] = "AAAAA"; tempWord = createWordStruct(temp1); addFirst(tempWord, &head); printf("\n\n-----------Printing List Adding First the word \"AAAAA\"-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); char temp2[6] = "ZZZZZ"; tempWord = createWordStruct(temp2); addLast(tempWord, &head); printf("\n\n-----------Printing List Adding Last the word \"ZZZZZ\"-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); char temp3[6] = "XXXXX"; tempWord = createWordStruct(temp3); addIndexed(tempWord, &head, 2); char prevWord[MAX], postWord[MAX]; strcpy(prevWord,((Word*)(head->next->data))->wrd); strcpy(postWord,((Word*)(head->next->next->next->data))->wrd); printf("\n\n-----------Printing List Adding at Index #2 the word \"XXXXX\"-----------\n\n"); printf("\n\n-----------It should be between the words \"%s\" and \"%s\"-----------\n\n", prevWord, postWord); printList(head); printf("\n\n\nBREAK\n\n\n"); removeFirst(&head); printf("\n\n-----------Printing List Removing First which will be the word \"AAAAA\"-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); removeLast(&head); printf("\n\n-----------Printing List Removing Last which will be the word \"ZZZZZ\"-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); printf("\n\n-----------Attempting to remove at index out of bounds-----------\n\n"); removeIndex(&head,-30); char word2Remove[MAX]; strcpy(word2Remove,((Word*)(head->next->next->data))->wrd); printf("\n\n-----------Attempting to remove at index 2 which will be: \"%s\"-----------\n\n", word2Remove); removeIndex(&head, 2); printf("\n\n-----------Printing list having removed %s-----------\n\n", word2Remove); printList(head); printf("\n\n\nBREAK\n\n\n"); printf("\n\n-----------Clearing (freeing) the entire list-----------\n\n"); clearList(&head); printf("\n\n-----------Attempting to print empty list-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); printf("\n\n-----------GOODBYE-----------\n\n"); fclose(fin); return 0; }// end main
int main( int argc, char* argv[ ] ) { Playlist *myList = NULL; int minutes, seconds; char *name, *title, *artist; Option opt; printf("\n\nWelcome to project 5 - music playlists\n\n"); opt = getAction(); while (opt != QUIT) { switch (opt) { case ADD_LIST: printf("Adding a new playlist to start of library\n"); name = getString("Enter the name of the new playlist"); printf("\nAdding the playlist '%s' to your library (at front of library) \n", name); myList = add(myList, name); break; case ADD_SONG: printf("Add a song to an existing playlist\n"); name = getString("Enter the name of the playlist"); title = getString("Enter the title of the song to add"); artist = getString("Enter the name of the artist"); getTime(&minutes, &seconds); printf("\nAdding the song below to the playlist '%s' (at end of playlist)\n", name); printf("\tTitle : %s\n", title); printf("\tArtist: %s\n", artist); printf("\tLength: %d:%d\n", minutes, seconds); addSong(myList, name, title, artist, minutes, seconds); break; case PRINT_LIST: printf("Print the songs in a playlist\n"); name = getString("Enter the name of the playlist"); printf("\nPrinting the names of all songs in the playlist '%s'\n", name); printSongs(myList, name); break; case LIST_SIZE: printf("Print the size of a playlist\n"); name = getString("Enter the name of the playlist"); printf("\nThe playlist '%s' contains N songs and has NN:NN minutes of music\n", name); printSize(myList, name); break; case STATS: printf("Print statistics on all your playslists\n"); printStats(myList); break; case ADD_LIST_ORDERED: printf("Adding a new playlist to library (ordered)\n"); name = getString("Enter the name of the new playlist"); printf("\nAdding the playlist '%s' to your library (in alphabetical order)\n", name); myList = addOrdered(myList, name); break; case ADD_SONG_ORDERED: printf("Add a song to an existing playlist (ordered)\n"); name = getString("Enter the name of the playlist"); title = getString("Enter the title of the song to add"); artist = getString("Enter the name of the artist"); getTime(&minutes, &seconds); printf("\nAdding the song below to the playlist '%s' (in alphabetical order)\n", name); printf("\tTitle : %s\n", title); printf("\tArtist: %s\n", artist); printf("\tLength: %d:%d\n", minutes, seconds); addSongOrdered(myList, name, title, artist, minutes, seconds); break; case REMOVE_SONG: printf("Removing a song from an existing playlist\n"); name = getString("Enter the name of the playlist"); title = getString("Enter the title of the song to remove"); artist = getString("Enter the artist of the song to remove"); printf("\nRemoving the song '%s' by '%s' from the playlist %s\n", title, artist, name); removeSong(myList, name, title, artist); break; case REMOVE_LIST: printf("Removing a playlist\n"); name = getString("Enter the name of the playlist to remove"); printf("\nRemoving the the playlist %s from your library\n", name); myList = removeList(myList, name); break; case HELP: optionDetails(); break; default: break; } opt = getAction(); } return 0; }