Question

In: Computer Science

MUST BE DONE IN C (NOT C++) This program should utilize the basics of strings. First,...

MUST BE DONE IN C (NOT C++)

This program should utilize the basics of strings. First, declare and initialize a string. You can name the variable whichever way you want and you can initialize it to whichever value you want. Then, use a for loop to print its characters; one at a time, until you reach the null character. After this, go ahead and declare a second string (since you are not initializing it right away, you will have to specify its length). This string should be long enough to hold all the characters of your first string (plus the null character).

The part 2 of this problem, is to copy the first string into the second one in reverse order. For example, if one string was “Hello World”, then the second string will be “dlroW olleH”. Don’t forget to assign the null character at the end of your second string.

When done, go ahead and use the %s printing method to print the second string.

Solutions

Expert Solution

For detailed description , read the comments in code:-

#include <stdio.h>
int main()
{
   char string1[1000];
   char string2[1000];
      char string3[1000];
   int begin, end, count = 0;

   //get string1 input from users
   printf("Input a string to reverse it \n");
   gets(string1);

   // Calculate the length of string1 here

   while (string1[count] != '\0')  //check for the null value in string which is present at last position to get the length of string1 
      count++;

   end = count - 1;

//////this for loop will reverse the content of string1
   for (begin = 0; begin < count; begin++) {
      string2[begin] = string1[end];  //index 0 of string2 will store the last value of string1  
      end--;             //here decrease the length of string1 by 1 and for loop will start again
   }

   string2[begin] = '\0';

   printf("The reverse string is:- \n");
   printf("%s\n", string2);

   return 0;
}


Related Solutions

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...
(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...
This program should be done in python. This must use the principles of object oriented program....
This program should be done in python. This must use the principles of object oriented program. Create one or more classes to play Four-in-a-Row (also called Connect Four) with a user. It’s similar to tic-tac-toe but the board is of size 7×6 and discs fall straight through so the legal moves are more stringent than tic-tac-toe. The state of the board should be printed to the terminal after each legal move. You can represent the different colored discs as X’s...
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases...
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases in which the initial unit is Fahrenheit or something not recognizable. Your program should incorporate Fahrenheit to Celsius, Fahrenheit to Kelvin and unknown initial units (display an error message for this last one). You must use functions to calculate Fahrenheit degrees.
Must be done in C Write a C program found out the maximum value between the...
Must be done in C Write a C program found out the maximum value between the three numbers? Show steps with comments or else it will be flagged.
(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…)....
Write a program in C++ that will make changes in the list of strings by modifying...
Write a program in C++ that will make changes in the list of strings by modifying its last element. Your program should have two functions: 1. To change the last element in the list in place. That means, without taking the last element from the list and inserting a new element with the new value. 2. To compare, you need also to write a second function that will change the last element in the list by removing it first, and...
IN C LANGUAGE This program will read in a series of strings and print only the...
IN C LANGUAGE This program will read in a series of strings and print only the consonants (including Y) until the word "stop" appears. No string will be longer than 100 characters. A consonant is any letter that is not a vowel. Don't forget to follow the standard read pattern! Examples Enter a string: Hello Hll Enter a string: World! Wrld Enter a string: 123! Enter a string: stop Enter a string: stop
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
Must be done with the Program Raptor Program #2 - Area of Shapes Design a superclass...
Must be done with the Program Raptor Program #2 - Area of Shapes Design a superclass called Shape that contains two functions—getVolume() and getInput(). The getVolume and getInput functions in the Shape class will simply return 0, you will derive from them in your subclasses mentioned below. Define 3 subclasses of the Shape class—Sphere, Cube, and Cone. The sphere class will need a radius field, the cube class will need a length field, and the cone class will need radius...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT