Question

In: Computer Science

(MUST BE DONE IN C (NOT C++)) In this task, you will have to make sure...

(MUST BE DONE IN C (NOT C++))

In this task, you will have to make sure you understood the concept of “the dot” in programming. Go ahead and declare an array of characters with a default length (whichever length you want, it's fine). Next, you want to ask the user for a phrase and store the characters in your array, but before you do that, ask the user for an estimated length of the array. If the length given is greater than the default length, display an error message and terminate the program. Otherwise, use an infinite loop (any kind of loop is fine) to scan the phrase, and let the user know that he/she should end the phrase with a dot. This dot will be used at the end the loop. When done, go ahead and print your array (by taking advantage of the dot). The goal of this assignment though, is to make sure you are also saving the dot in your array, because if you are not, your loop might not end when you want it to. So if the dot is not printing in the terminal right after the inputted phrase, there is something wrong with your array.

Solutions

Expert Solution

#include <stdio.h>

int main(void) {

int n;

printf("How many characters do you want to enter? ");

scanf("%d", &n);

char strs[n];

int counter = 0;

char inp;

while(counter <= n || inp != '.')

{

printf("Enter a character (. to stop): ");

scanf(" %c", &inp); // space before %c consumes the newline after the input

if(counter > n || inp == '.')

break;

strs[counter++] = inp;

}

// display the string

printf("\nThe string is: ");

for(int i = 0; i < counter; i++)

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

printf("\n");

return 0;

}

******************************************************** SCREENSHOT ********************************************************

CODE SCREENSHOT :

CONSOLE OUTPUT :


Related Solutions

(MUST BE DONE IN C (NOT C++)) In this task, you will create a structure with...
(MUST BE DONE IN C (NOT C++)) In this task, you will create a structure with arrays. You will have to create your own structure. However, make sure to meet these guidelines: - Give the structure whichever name you want. - It must have at least 3 members. - Two of the members must be arrays. - Your members should be of at least two different data-types. In other words, your members cannot be integers only (or floats, or doubles…)....
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add...
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add a range of values of an array. The range will be determined by the user. For example, if I have the following array … 1.5 -5.6 8.9 4.6 7.8 995.1 45.1 -5964.2 … and the user tells me to add from the 3rd element to the 6th element, my program would add the values 8.9, 4.6, 7.8 and 995.1. To do so, please follow...
C++ questions, please make sure to dividet he program into functions which perform each major task,...
C++ questions, please make sure to dividet he program into functions which perform each major task, A leap year is defined as any calendar year which meets the following criteria: If the year is not divisible by 4, it is a common year If the year is not divisible by 100, it is a leap year If the year is not divisible by 400, it is a common year Otherwise it is a leap year For your program you will...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of x students’ grades (grades will be stored in an array). To do so, please follow these guidelines: - Your program should ask the user for the number of students that are in the class. This number should help you declare your array. - Use the function seen in class to scan the grades of the array. In other words, we will populate the array...
Task: Write a program that creates a class Apple and a tester to make sure the...
Task: Write a program that creates a class Apple and a tester to make sure the Apple class is crisp and delicious. Instructions: First create a class called Apple  The class Apple DOES NOT HAVE a main method  Some of the attributes of Apple are o Type: A string that describes the apple. It may only be of the following types:  Red Delicious  Golden Delicious  Gala  Granny Smith o Weight: A decimal value representing...
MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a...
MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a university’s profile (you can pick any university name, just so long as the program runs properly). The structure must contain 5 members: - One member for number of undergraduate students - One member for number of graduate students - One member for number of classrooms - One member for the name of the university (an array) - One member for the term (fall, summer...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values of an array backwards. Please follow these guidelines: - Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer). - Call your function. You should send two parameters to such function: the array’s length and the array. - Inside the function, go ahead and print the array backwards. - Your function shouldn’t return anything
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches....
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches. First, ask the user for the name of students they have in their class. Then, using a loop, you will ask for each student’s height. However, you will have to use two separate variables, one for feet and one for inches. Then, you will have to call two functions. The first function will check if the values entered are valid (check if number of...
Write code for a game of picking match sticks. You must make sure that the computer...
Write code for a game of picking match sticks. You must make sure that the computer always wins. The game is as follows There are 26 matchsticks initially. The computer will ask the user to pick anywhere between 1 and 4 matchsticks. The player (whether the user or the computer) who has to pick up the last matchstick (or matchsticks) is the loser. You will have to use a combination of branching and looping commands with appropriate prompts and the...
needs to be done in C++ Q6. Coding Question (you must code this problem and submit...
needs to be done in C++ Q6. Coding Question (you must code this problem and submit via Blackboard): Keep everything as Integers. Row and Column Numbering starts at 1. Equation for each Cell :   Coll = (Row * Col * 10) Using Nested Loops display the following exactly as it is shown below:                                  Columns % Brand         1           2         3          4               A            10         20       30       40          B            20         40        60       80           C            30         60        90    ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT