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

A user will enter one line of text at a time. Use EOF or ‘\ ’ to determine end o

ID: 3668287 • Letter: A

Question

A user will enter one line of text at a time. Use EOF or ‘ ’ to determine end of the input

Echo the input one word per line and capitalize each word. Do not use toupper().

Any non-letter ( white spaces, special characters (*, &,+, etc.), numbers, and punctuation marks) will serve as delimiters

There will be only one delimiter between words A sentence may start or end with a delimiter

Do not output delimiters

A user may enter as many line as he/she wishes

Clearly label the output

Well document your code (comments)

Do not use arrays or any built-in functions

NO goto, continue, break (except for switch)

Explanation / Answer

/* C/C++ program to count no of words from given input string. */
#include <stdio.h>

#define OUT 0
#define IN 1

// returns number of words in str
char* wordTitler(char *str,char* output)
{

int x=0;// output index;
int state = OUT;

// Scan all characters one by one
while (*str)
{
// If next character is a separator, set the
// state as OUT
char c = *str;
if ((c >='a' && c <='z') || (c >= 'A' && c <= 'Z')){
               if(state == OUT){
                   if((c>='a')&&(c<='z'))
                       c=c-32;
                       output[x++] =' ';
                   }
              // printf("%c",c);// instead of printing reault you can store in array
               output[x++] = c;
           state = IN;
           }

// If next character is not a word separator and
// state is OUT, then set the state as IN and
// increment word count
else
{   //printf("sdwd ");
           if(state == IN){
              // printf(" ");
           }
           state = OUT;

}

// Move to next character
++str;
}
output[x] = '';
return output;
}

// Driver program to tes above functions
int main(void)
{
char output[50];
char str[] = "One two three four five ";
char str1[] = "Student identification number, type of room2R, A? number’s of units*";
wordTitler(str,output);
printf(" ");
printf("%s ",output);
wordTitler(str1,output);
printf(" ");
printf("%s ",output);
return 0;
}

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