Question

Write a program that reads in a sentence of up to
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: Program #include #include <stdio.h> <string.h> int main ( ) char c[100] int ii.len; printf (Enter a string : ) scanSample Output: Enter a string : abcd xyZiw Abcd Xyzw sh-4.3$ main Enter a string : abcd iJKlm Abcd Ijklm Nopq sh-4.3$ noPq

Copyable Code:

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

int main()
{
char c[100];
int i,j,len;
printf ("Enter a string : ");
scanf ("%[^\n]%*c", c);
len = strlen(c);
c[0] = c[0] - 32;
for (i=0; i<len; i++)
{
while(c[i] == c[i+1])
{
if (c[i] == ' ' && c[i+1] == ' ')
{
for(j=i+1; j<len; j++)
c[j] = c[j+1];
len--;
}
}

if (c[i] == ' ' && c[i+1] != ' ')
{
if (c[i+1] >= 'a' && c[i+1] <= 'z')
c[i+1] = c[i+1] - 32;
}
else
if (c[i+1] >= 'A' && c[i+1] <= 'Z')
c[i+1] = c[i+1] + 32;
  
}
printf("%s\n",c);
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a program that reads in a sentence of up to 100 characters and outputs the...
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
  • A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here...

    A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for the user input....

  • Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward...

    Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for...

  • C++ programming: Write a program to score a two player game of scrabble. The program reads...

    C++ programming: Write a program to score a two player game of scrabble. The program reads the player number, word played and the squares on the board used for each word played then reports the scores for each word and the total score for each player. • All information is read from the file, moves.in. • Each line of the file contains a player number (1 or 2), the word and the board spaces used. • The words are entered...

  • Write a C++ program that repeatedly reads lines until an EOF is encountered. As each line...

    Write a C++ program that repeatedly reads lines until an EOF is encountered. As each line is read, the program strips out all characters that are not upper or lower case letters or spaces, and then outputs the line. Thus, the program acts as a filter and issues no prompt. There are many ways this program could be written, but to receive full credit, you must observe the following: Place your code in a file called filterChars.cpp. The program should...

  • Write a function named words_in_both that takes two strings as parameters and returns a set of...

    Write a function named words_in_both that takes two strings as parameters and returns a set of the words contained in both strings. You can assume all characters are letters or spaces. Capitalization shouldn't matter: "to", "To", "tO", and "TO" should all count as the same word. The words in the set should be all lower-case. For example, if one string contains "To", and the other string contains "TO", then the set should contain "to". You can use Python's split() funciton,...

  • 1. Write a python program that reads a file and prints the letters in increasing order...

    1. Write a python program that reads a file and prints the letters in increasing order of frequency. Your program should convert entire input to lower case and only counts letters a-z. Special characters or spaces should not be counted. Each letter and it's occurrences should be listed on a separate line. 2. Test and verify your program and it's output. ---Please provide a code and a screenshot of the code and output. Thank you. ----

  • Write a program that reads a string entered at the command line and counts the number...

    Write a program that reads a string entered at the command line and counts the number of characters or words. A blank space should be used to delimit a word. Name the program StringCount and design it to be invoked using syntax as follows: StringCount –[c][w] user_string

  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • Write a C program named space_to_line.c that features a while loop that continuously reads input from...

    Write a C program named space_to_line.c that features a while loop that continuously reads input from the user one character at a time and then prints that character out. The exception is that if the user inputs a space character (‘ ‘), then a newline character (‘\n’) should be printed instead. This will format the output such that every word the user inputs is on its own line. Other than changing the spaces to newlines, the output should exactly match...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

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
ADVERTISEMENT