The getchar function in the stdioh library reads a single c

The getchar ) function in the stdio.h library reads a single character from the user and returns it as a value of type char). The ctype.h header file contains several useful functions for working with char values, including the following: . isspace (c) -Returns true if the character c is any kind of space (including a newline or a tab character) and false otherwise. isalpha (c) -Returns true if the character c is a letter (uppercase or lowercase) and false otherwise. . isdigit (c) -Returns true if the character c is a digit (0 through 9) and false otherwise. islower (c)-Returns true if the character c is a lowercase letter and false otherwise. isupper (c) -Returns true if the character c is an uppercase letter and false otherwise. . tolower (c) -Returns the lowercase version of the provided character c. toupper (c) -Returns the uppercase version of the provided character c. A syntactically correct C program has been provided in the file A4P2_2016_Template.c (posted on CourseSpaces). As written, the template program reads a single line of text from the user and prints each character on a line by itself. The result of a sample run of the unmodified template is shown below Enter a line of text: Hello World Character: H Character e Character: 1 Character: 1 Character: o Character: (space) Character: W Character: o Character r Character 1 Character: d

Solution

//Tested on ubuntu,Linux

#include <stdio.h>
#include <string.h>
#include <ctype.h>
void strOperation(char* input){
   /*Calculating length of input char array*/
   int len=strlen(input);
  
   int i=0;
   /*Iterating through for loop
   * and checking every value is character or Digit*/
   for(i=0;i<len;i++) {
       if(isspace(input[i])) {
           printf(\"Character: (space)\ \");          
       }else if(isalpha(input[i])) {
           printf(\"Character: %c\ \",input[i]);
       }else if(isdigit(input[i])) {
           printf(\"Digit: %c\ \",input[i]);
       }
      
   }
  
}
void captialFirstLetter(char *input) {
  
   /*Calculating length of input char array*/
   int len=strlen(input);
  
   int i=0;
   int flag=1;
   /*Iterating through for loop
   * we are using a flag to check it is first letter of word or not
   * if it is then making it capital letter*/
   for(i=0;i<len;i++) {
       if(!isspace(input[i])&&flag==1){
           printf(\"%c\",toupper(input[i]));
           flag=0;
       }else if(isspace(input[i])) {
          
           printf(\"%c\",input[i]);
           flag=1;
       }else {
          
           printf(\"%c\",tolower(input[i]));
       }
   }
   printf(\"\ \");
  
  
}

int main(){
/*variable declaration*/
char input[200];

/*Prompt for user input*/
printf(\"Please Enter the string input: \");
gets(input);
/*Calling String Operation function*/
printf(\"*************String operation start**********\ \");
strOperation(input);
printf(\"*************Capatialized word string********\ \");
/*Calling first letter of word captial function*/
captialFirstLetter(input);

return 0;
}


/*************output*************/

anshu@anshu:~/Desktop/chegg$ gcc StringOper.c
StringOper.c: In function ‘main’:
StringOper.c:57:1: warning: implicit declaration of function ‘gets’ [-Wimplicit-function-declaration]
gets(input);
^
/tmp/cc5DJXqp.o: In function `main\':
StringOper.c:(.text+0x28e): warning: the `gets\' function is dangerous and should not be used.
anshu@anshu:~/Desktop/chegg$ ./a.out
Please Enter the string input: Hello World
*************String operation start**********
Character: H
Character: e
Character: l
Character: l
Character: o
Character: (space)
Character: W
Character: o
Character: r
Character: l
Character: d
*************Capatialized word string********
Hello World
anshu@anshu:~/Desktop/chegg$ ./a.out
Please Enter the string input: west virginia
*************String operation start**********
Character: w
Character: e
Character: s
Character: t
Character: (space)
Character: v
Character: i
Character: r
Character: g
Character: i
Character: n
Character: i
Character: a
*************Capatialized word string********
West Virginia

Thanks a lot

 The getchar ) function in the stdio.h library reads a single character from the user and returns it as a value of type char). The ctype.h header file contains
 The getchar ) function in the stdio.h library reads a single character from the user and returns it as a value of type char). The ctype.h header file contains
 The getchar ) function in the stdio.h library reads a single character from the user and returns it as a value of type char). The ctype.h header file contains

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site