Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me fix this C program. I will display the assignment and then my code that contains error and needs to be fixed. I

Please help me fix this C program.

I will display the assignment and then my code that contains error and needs to be fixed.

I want my code to run fluently according to what is ordered for me.

image text in transcribed

#define _CRT_SECURE_NO_WARNINGS

#define PAUSE system("pause")

#define CLS system("cls")

#define FLUSH myFlush()

#include

#include

#include

// structs

typedef struct {

char word[15];

int numOfVowels;

}WORDS;

// user defined functions

WORDS* makeAWord();

void addWord(WORDS* myWords);

void displayMenu();

void displayWordsInABCOrder(WORDS** myWords, int count);

void freeMemory(WORDS** myWords, int count);

int getChoice();

void myFlush();

void saveWords(WORDS* myWords, int *counter);

void loadWords(WORDS* myWords, int *counter);

int main() {

WORDS** myWords;

char choice = ' ';

int count = 0;

myWords = calloc(500, sizeof(WORDS*));//*** DO NOT FORGET TO CHANGE THIS!!!!!!!!!!!!

loadWords(myWords, &count);

do {

choice = getChoice();

switch (choice) {

case 'E':// Enter a new word

myWords[count] = makeAWord();

addWord(myWords[count]);

count++;

break;

case 'P'://Print all words

displayWordsInABCOrder(myWords, count);

break;

case 'D'://Display all words that begin with a certain letter

break;

case 'Q':// Quit

saveWords(myWords, count);

printf(" \t Thanks for Playing!!!");

freeMemory(myWords, count);

PAUSE;

exit(-1);

break;

default:

printf("********************************************** ");

printf("**** Invalid Selection! Please try again ***** ");

printf("********************************************** ");

PAUSE;

CLS;

break;

return;

}

} while (choice != 'Q');

PAUSE;

}//end main

void addWord(WORDS *myWords) {

printf("Enter Word: ");

scanf("%s", myWords->word); FLUSH;

}

void displayWordsInABCOrder(WORDS** myWords, int count) {

int i, j;

char temp[25];

for (i = 0; i

for (j = i + 1; j

if (strcmp(myWords[i]->word, myWords[j]->word) > 0) {

strcpy(temp, myWords[i]->word);

strcpy(myWords[i]->word, myWords[j]->word);

strcpy(myWords[j]->word, temp);

}

}

printf("Order of Sorted words is :");

for (i = 0; i

printf("%s",&myWords[i]->word);

PAUSE;

return 0;

}

void displayMenu() {

CLS;

printf(" ");

printf("************ MENU *************** ");

printf("\t [E]nter a new word ");

printf("\t [P]rint all words ");

printf("\t [D]isplay all words that begin with a certain letter ");

printf("\t [Q]uit ");

} // end displayMenu

void freeMemory(WORDS** myWords, int count) {

int i;

for (i = 0; i

printf("%i. %p has been freed ", i, myWords[i]);

free(myWords[i]);

}// end for

printf("The array at %p is freed. ", myWords);

free(myWords);

} // end freeMemory

int getChoice() {

char result;

displayMenu();

scanf("%c", &result);

return toupper(result);

} // end getChoice

void myFlush() {

while (getchar() != ' ');

}//end myFlush

void saveWords(WORDS myWords[], int counter) {

FILE *ptr; // creates pointer file

ptr = fopen("Words.bin", "wb"); // opens for writing

if (ptr == NULL) {

printf("Error saving data, please contact support center. ");

PAUSE;

exit(-1);

}// end if

fwrite(myWords, sizeof(myWords), 100, ptr); // save

fwrite(&counter, sizeof(int), 1, ptr);

fclose(ptr);

}

void loadWords(WORDS myWords[], int *counter) {

int i = 0;

FILE *ptr;

ptr = fopen("Cars.bin", "rb"); // opens for reading

if (ptr == NULL) {

printf("Error load data, please contact support center. ");

PAUSE;

}

else {

fread(myWords, sizeof(myWords), 100, ptr); // reads back the cars

fread(&*counter, sizeof(int), 1, ptr);

fclose(ptr);

}

}

WORDS* makeAWord() {

WORDS* result;

result = malloc(sizeof(WORDS));

return result;

}

Words with constants and vowels Allow the user to enter a word. You are to store the word. .The user can enter between 1 and 500 thousand words. You are to store the words in a dynamic array on the heap in disjoint memory. You are to sort the words in alphabetical order Along with each word you are to store the number of constants and vowels within the word .The user can output all words or only words that begin with a selected letter. When the user selects Quit, you will save the word list, when the program starts back up, you will reload the list (if found). [E]nter a new word [Plrint all words Dlisplay all words that begin with a certain letter Qluit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago