Write a C program that
a. Asks for a sentence (max 80 characters) or “quit” to quit.
b. Uses a helper function to print a right triangle of each letter in the sentence with the spaces removed. (It is ok if the last line of the triangle is not a full line.) In other words, first print a line with one character, print the next line with one more character than the previous line, and repeat that pattern until you run out of non-space characters.
c. Goes back to step a. (e.g. starts the program again).
• You will have to look up how to ask for input! Look up fgets() using the man pages with this commands on the student server: man fgets You will want to be sure to include the right libraries at the top of your program to use with fgets. The libraries needed will be shown at the top of the man page. • Quotes matter. Single quotes go around a single character. Double quotes go around a string. Strings are really just character arrays, so don’t be afraid to index into them. • Do not use static or global variables to implement the assignment
#include <stdio.h>
#include <string.h>
void printTriangle(char *str);
int main(){
char sentence[81];
int done = 0;
while(done != 1){
printf("Enter a sentence(type quit to stop)\n");
fgets(sentence, 80, stdin);
if(strcmp(sentence, "quit\n") == 0) //comparing along with \n since fgets() returns string with \n
done = 1;
else
printTriangle(sentence);
}
}
void printTriangle(char *str){
int index = 0;
int line = 1;
int i;
while(str[index] != '\0'){
for(i = 1; i <= line; index++){
if(str[index] == ' ')
continue;
else if(str[index] == '\0')
break;
printf("%c",str[index]);
i++;
}
line++;
printf("\n");
}
printf("\n");
}
Write a C program that a. Asks for a sentence (max 80 characters) or “quit” to...
Write a program that reads in a sentence of up to 100 characters and outputs the sentence with spacing corrected and with letters corrected for capitalization. In other words, in the output sentence, all strings of two or more blanks should be compressed to a single blank. The sentence should start with an uppercase letter but should contain no other uppercase letters. Do not worry about proper names; if their first letters are changed to lowercases, that is acceptable. Treat...
C Code Create a tool in which a user can enter a string (up to 25 characters) and choose how they wish to manipulate the string from a menu your program will display (see the run-through). The program will continue to ask for commands until the user enters the “quit” command. The commands are: • “Replace All” If a user types “replace all” using ANY sort of capitalization, your program will prompt the user to enter the character to change...
IN C++ Write a program in c++ that will read from a file the following sentence: The quick brown fox jumps over the lazy dog Each word must be read into one location in an array beginning with the first element. You must declare an array as follows: char *words [9] ; // this is an array of c- strings. HINT words[0] will contain "the" words[1] will contain "quick" write a function int length (const char *a) to determine the...
C++
Write a program that asks for a number and then prints as many
lines as the user inputs. Each line contains as many pairs of
characters ("*#") as the number of this line. It should look like
the right half of a pyramid. Your version of the program must print
the same result as the expected output. To to this lab, you must
use two do-while loops.
Two exceptions:
When the user inputs a number less than 1, then...
Use c-strings for the following project: Write a C++ program that declares an array containing up to a maximum of 20 sentences, each sentence of maximum 81 characters long, using c-strings. Continue reading sentences from the user and store them in the array of sentences, until the user enters a NULL string for the sentence or 20 sentences have been entered. Then, one by one, display each sentence entered by the user and present the following menu of operations on...
Concepts: Pointers and pointer arrays Write a program to read in a phrase from the keyboard, re-display the text, and display a message on the following line giving the text's status as a palindrome. Do not use any arrays or subscripting in this program, except for arrays of pointers. A palindrome is a word or phrase which is the same backwards as forwards; for example "civic", "toot", and "radar" are palindrome words; each word is spelled the same left to...
Write a C program which will display the contents of a file in base-16 (hexadecimal) and in ASCII. Complete the following tasks: Obtain the name of the input file from the command line. If the command-line is “./hexdump xxx.bin” then argv[1] will contain “xxx.bin”. Open the file for binary input Print the entire file, 16-bytes per line. Each line should begin with an 8-digit hexadecimal offset into the file. This is the count of the bytes that you have already...
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...
Update the program in the bottom using C++ to fit the requirements specified in the assignment. Description For this assignment, you will be writing a single program that enters a loop in which each iteration prompts the user for two, single-line inputs. If the text of either one of the inputs is “quit”, the program should immediately exit. If “quit” is not found, each of these lines of input will be treated as a command line to be executed. These...
This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...