Question

Using C programming

Write a program that asks the user for a sentence and displays the following four things. They are in increasing order of difficulty.

  1. How many characters in that sentence? [12]

  2. How many words in that sentence? [3]

  3. The sentence backwards [dooG sI efiL]

  4. The words (not the letters) shown in reverse order (not mandatory! this one is hard!!) [Good Is Life]


0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>


int main(){

   int i,j;

   char str[]="Life Is Good";

   printf("Length of sentence : %d\n",strlen(str));

   int words=1;

   int indices[10];

   char strrev[sizeof(str)];

   char strwordsrev[sizeof(str)];

   int k;

   k=0;

   for(i=0;i<strlen(str);i++){

      if(str[i]==' '){

         words=words+1;

         indices[k]=i;

         k=k+1;

      }

   }

   indices[words-1]=strlen(str);

   printf("Words in sentence: %d\n",words);

   for(i=strlen(str);i>=0;i--){

      strrev[strlen(str)-1-i]=str[i];

   }

   printf("Sentence in reverse: ");

   for(i=0;i<strlen(strrev);i++){

      printf("%c",strrev[i]);

   }

   printf("\nWords in reverse: ");

   int temp=0;

   for(i=0;i<words;i++){

      j=0;

      while(1){

         printf("%c",strrev[indices[i]-j]);

         j=j+1;

         if((indices[i]-j)==temp-1){

            temp=indices[i];

            break;

         }

      }

   }

   

   

}


answered by: codegates
Add a comment
Know the answer?
Add Answer to:
Using C programming
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write another function called checkdiag2 (int checkdiag2 (int matrix[][100], int size)) that will return 1 if...

    Write another function called checkdiag2 (int checkdiag2 (int matrix[][100], int size)) that will return 1 if all the numbers on the antidiagonal are the same and 0 otherwise. Rewrite your main program to use 2D dynamic allocation instead for your array. Your array will have rows and columns depending of the first integer read from the file. Call your function from the main program. A typical report would look like The matrix is 8x8 and all the numbers on the...

  • write a program in java that asks the user for a sentence, and then returns that...

    write a program in java that asks the user for a sentence, and then returns that string with the words backwards. For example: Enter a sentence! Mary had a little lamb. Your sentence backwards: lamb. little a had Mary Write a method called reverse() that accepts a sentence as a string, and then returns that string with the words backwards. Write a main() method that gets the string from the user and then displays the string backwards. demonstrate program by...

  • In c programming, I need to write a program that reverses each of the lines in...

    In c programming, I need to write a program that reverses each of the lines in a file. The program accepts two command line arguments: The first one is the name of the input file The second is the name of the output file If the user didn't give two filenames, display an error message and exit. The program reads in each line of the input file and writes each line in reverse to the output file. Note, the lines...

  • Create a data file named REVERSE.TXT and type the sentence                        EVERY GOOD BOY & GIRL...

    Create a data file named REVERSE.TXT and type the sentence                        EVERY GOOD BOY & GIRL DOES FINE                                                                                  Write a C++ program that retrieves the phrase stored in the       the data file REVERSE.TXT and immediately displays the phrase    on the screen. Then your program displays the phrase where      each word is reversed. Notice you’re not reversing the entire sentence. The order of the words remains the same. However,    the spelling of each word is reversed! EXAMPLE:...

  • matlab code Question : Not yet answered Marked out of 10.00 Flag question Build a MATLAB...

    matlab code Question : Not yet answered Marked out of 10.00 Flag question Build a MATLAB program that asks the user to enter a string which is composed of an English sentence that has at least 5 words. Your task is to build a function that counts and displays the number of words inside the sentence. Additionally, you need to build another function that displays the whole sentence in reverse order without using the bulk in function reverse Paragraph в...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • Please help with writing this code. The language is C++. I'm using vim. Thanks Problem Statement...

    Please help with writing this code. The language is C++. I'm using vim. Thanks Problem Statement A good password has many requirements. Humans have a hard time meeting these requirements left to their own devices. You are tasked with creating a program that will generate a password based on what the user wants in the password The user should be able to choose if they want a password with: letters upper case "lower case *numbers The user should also provide...

  • Write a program in java that asks a user for a file name and prints the...

    Write a program in java that asks a user for a file name and prints the number of characters, words (separated by whitespace), and lines in that file. Then, it replaces each line of the file with its reverse. For example, if the file contains the following lines (Test1.txt): This is a test Hi there Output on the console: Number of characters: 22 Number of words: 6 Number of lines: 2 Data written to the file (Test1.txt): tset a si...

  • Description -- Microsoft Studio, Visual Basic Problem 6.1 Words Reversed - Write a program that uses...

    Description -- Microsoft Studio, Visual Basic Problem 6.1 Words Reversed - Write a program that uses a Do Loop so that the user may enter words using a popup Input Box. Once the user enters "STOP" , the program then displays all the words in a single string. The difficulty is that the words are displayed in reverse order with spaces. The program is initiated with a button. For example: The following words are entered separately one at a time:...

  • In c++ please .. Write a program that prompts the user to enter a four-digit integer...

    In c++ please .. Write a program that prompts the user to enter a four-digit integer and displays the number in reverse order.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT