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

You might recognize the code on the next page as being the wds.c program from th

ID: 3703891 • Letter: Y

Question

You might recognize the code on the next page as being the wds.c program from the text and spell checker fame. Modify this program to print each word on a separate line with the phrase “has double letters” after any word that has the same letter twice adjacent to each other in the word.

For example, the input:

would output:

Ever really looked at the moon, Lloyd?

Ever

really has double letters

looked has double letters

at

the

moon has double letters

Lloyd has double letters

/* File: tfdef.h */
#define TRUE 1
#define FALSE 0

#include <stdio.h>

#include "tfdef.h"

#include "chrutil.h"

main()

{ signed char ch;

int inword,

lns, wds, chrs;

/* flag indicating when in a word */

/* Counters for lines, words, chars. */

} }

lns = wds = chrs = 0; /* initialize counters to 0 */

inword = FALSE; /* before beginning we are not in a word */

while ((ch = getchar()) != EOF) /* while there are more chars */

{ chrs = chrs + 1;

if (ch == ’ ’)

/* count characters */

/* if newline char */

/* count lines */

lns = lns + 1;

/* if not in a word and not a delimiter */

/* then this must be the beginning of a word */

if (!inword && !delimitp(ch))/* if not in word and not delim*/

{ inword = TRUE; /* remember we are in a word */

wds = wds + 1; /* count words */

}

/* otherwise if in a word, but found a delimiter */

/* then we just went beyond the end of the word */

else if (inword && delimitp(ch))/* if in word and a delim*/

{ inword = FALSE;

putchar(’ ’);

}

if (inword)

putchar(ch);

/* no longer in word */

/* end word with newline */

/* if in a word */

/* print the character */

Explanation / Answer

#include<studio.h>

#include "tfdef.h"

#include "chrutil.h"

main()

{

signed char ch, temp;

int count=0; // counter for adjacently duplicate characters

while ((ch = getchar()) != EOF) /* read each character while there are more chars */

{

if(ch!=''){ // '' is space, indicates end of current word

putc(ch); // display each character

if(strcmp(temp,ch)==0) // checks whether current letter is //same as the previous one

count++; // if same count is incremented

strcpy(temp,ch); // copies current character to a temp variable

}

else{ // current char is space, one word ended

if(count>0){ // checks for repetition of letters

printf("has double letters ");

count=0; // resets counter for next word

}

printf(" "); // prints next wors in next line

}

}

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