Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I need help with a c program that is suppose to take words from a word li

ID: 3564911 • Letter: H

Question

Hello, I need help with a c program that is suppose to take words from a word list. I have managed to get the program to display the 9-letter words in the word list. Now, I am suppose to cycle through the 9 letter words and remove a letter, and check to see if that word if contained in the words list. For example. say I have the 9 letter word

"aardvarks"

I have to remove each letter in the word and see check to see if the word is contained in the word list, which I believe I have to use strcmp for.

If I remove the letter "a", I am left with the word

"ardvarks"

which is not a real word,(I check this by running the word through the word list again). I must do this for every single letter. If I remove a "s", the word then becomes "aardvark" which is indeed a valid word. I must then copy try to reduce this word into a 7-letter word by the same process, and then a 6 letterword, 5 letter word and so on.

This is the code that I have written so far, but it's not giving me the results that I need.

#include<stdio.h>
#include<string.h>

int main()
{
FILE *ptr;
FILE *nine_words = fopen("nine_words.txt", "w+");
FILE *eight_words = fopen("eight_words.txt", "w+");
FILE *seven_words = fopen("seven_words.txt", "w+");
FILE *six_words = fopen("six_words.txt", "w+");
FILE *five_words = fopen("five_words.txt", "w+");
FILE *four_words = fopen("four_words.txt", "w+");
FILE *three_words= fopen("three_words.txt", "w+");
FILE *two_words = fopen("two_words.txt", "w+");
FILE *one_words = fopen("one_words.txt", "w+");
int iterator = 0,a,b,c,d,e,f,g,h,i,passed = 0;
char buf[10000];
char nine_letters[10000];
int length ;
char nine_word[10]; //arraysletters used to store the words that will be created
char eight_word[9];
char seven_word[8];
char six_word[7];
char five_word[6];
char four_word[5];
char three_word[4];
char two_word[3];
char one_word[2];
char lastword[10];
char testword[10];

ptr = fopen("words2.txt","r");

while (fscanf(ptr,"%s",buf)!=EOF)
{
length = strlen(buf);
if (length == 9 )
{
//printf("%s ",buf);
buf[10000] = nine_words[10000];
strcpy(buf,nine_words);
printf("%s ", nine_words);

}
}

ptr = fopen("nine_words.txt","r");
   for(a = 0; a < 9; a++) //iterate through letters (9 letter)
{
for(i = 0; i < 8; i++) //construct new word (8 letter)
{
if (i == a)
{
trigger = 1;
testword[i] = nine_words[i+trigger];
}
}

}
return 0;

In this code, I've managed to single out all the 9 letter words in the word list, but not much else.

Explanation / Answer

#include /* see 'fix' to remove ALL char's ... */ void removeChar( char cStr[], char let ); int main() { char myString[] = "Cats are black! Oh,... not always,... some are white also!"; printf( "Unmodified string: %s ", myString ); removeChar( myString, '.' ); printf( "Modified string: %s ", myString ); printf( " Press 'Enter' to continue ... " ); getchar(); return 0; } void removeChar( char cStr[], char let ) { unsigned i, j; /* need to declare at top for 'C' compile ... */ for( i = j = 0; cStr[i] != 0; ++i ) if( cStr[i] == let ) continue; else cStr[j++] = cStr[i] ; cStr[j] = 0; /* Now ... null terminate */ }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote