Question

In: Computer Science

Write an entire program (with a main function and necessary header files included) that declares an...

Write an entire program (with a main function and necessary header files included) that declares an 80 byte character buffer, prompts a user to enter a single word (no spaces) from the default input device (e.g. the keyboard), which is stored in the buffer, and then reverses the string while overwriting the buffer. Print the sting before and after the reversal. The program transcript should resemble the following output:

$ ./program.exe
enter string: nvidia
before: nvidia
after: aidivn

in C

Solutions

Expert Solution

Hello learner,

Thanks for asking.

Here is the C programming code to reverse a string.

#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
char str[80];
char rev[80];
printf("enter string:\t");
scanf("%s", str);
printf("before : %s\n", str);

// for loop is used to reverse the caracters //
for(i = 0; str[i] != '\0'; i++);
{
k = i-1;
}
for(j = 0; j <= i-1; j++)
{
rev[j] = str[k];
k--;
}
printf("after : %s\n", rev);
getch();
}

In this code at first input is taken from the user and then store it as a string type. After that by using for loop each and every caracter of the string is reversed one by one to the rev[ ] from str[ ]. when the loop is completed then reverse string is printed.

Here is the image of code with proper output.

use proper indentation for less error.

Please upvote and ask if you have any query.


Related Solutions

WRITE ONLY THE TO DO'S   in FINAL program IN C++ (necessary cpp and header files are...
WRITE ONLY THE TO DO'S   in FINAL program IN C++ (necessary cpp and header files are witten below) "KINGSOM.h " program below: #ifndef WESTEROS_kINGDOM_H_INCLUDED #define WESTEROS_KINGDOM_H_INCLUDED #include <iostream> namespace westeros { class Kingdom{         public:                 char m_name[32];                 int m_population; };         void display(Kingdom&);                      } #endif } Kingdom.cpp Program below: #include <iostream> #include "kingdom.h" using namespace std; namespace westeros {         void display(Kingdom& pKingdom) {                 cout << pKingdom.m_name << ", population " << pKingdom.m_population << endl;                                                               FINAL:...
Write a program in ecmascript, of Maclurin series of a sine function that declares two variables:...
Write a program in ecmascript, of Maclurin series of a sine function that declares two variables: x is the value of the argument, h is the accuracy that you want test the program with x= 1; h= .00001 print out the approximation using as many terms of the Maclaurin series that you need, but no more than that, to get within the required accuracy. While you are at it you might as well also print out Sine(x) BUT do not...
How do you use header files on a program? I need to separate my program into...
How do you use header files on a program? I need to separate my program into header files/need to use header files for this program.Their needs to be 2-3 files one of which is the menu. thanks! #include #include #include using namespace std; const int maxrecs = 5; struct Teletype { string name; string phoneNo; Teletype *nextaddr; }; void display(Teletype *); void populate(Teletype *); void modify(Teletype *head, string name); void insertAtMid(Teletype *, string, string); void deleteAtMid(Teletype *, string); int find(Teletype...
Write Program in C: Write a program that: program starts; declares and initializes to 7.25% constant...
Write Program in C: Write a program that: program starts; declares and initializes to 7.25% constant float variable NJSALES_TAX; declares and initializes to 1000 an integer variable total; declares and initializes to zero a float variable grand_total; prompt and input on new line total; calculate grand_total to equal total plus (total*NJSALES_TAX); if grand_total <= 1000 print on new line “Grand total is less than or equal to 1000 it is $” and the grand_total to two decimal places; else if...
Write a program that utilizes a function called paymentCalc. In the main body of the program,...
Write a program that utilizes a function called paymentCalc. In the main body of the program, ask the user what is their principal and how many months they want the loan. If it is easier, ask the user for number of years, but don’t forget to change it to months for the calculation. Use a function to calculate their monthly mortgage payment. In the main body of the program, print out what their monthly mortgage payment will be. For simplicity,...
Write the following function and provide a program to test it (main and function in one...
Write the following function and provide a program to test it (main and function in one .py) def repeat(string, n, delim) that returns the string string repeated n times, separated by the string delim. For example repeat(“ho”, 3, “,”) returns “ho, ho, ho”. keep it simple.Python
Write a C++ program which consists of several functions besides the main() function. The main() function,...
Write a C++ program which consists of several functions besides the main() function. The main() function, which shall ask for input from the user (ProcessCommand() does this) to compute the following: SumProductDifference and Power. There should be a well designed user interface. A void function called SumProductDifference(int, int, int&, int&, int&), that computes the sum, product, and difference of it two input arguments, and passes the sum, product, and difference by-reference. A value-returning function called Power(int a, int b) that...
Write a python program function to check the frequency of the words in text files. Make...
Write a python program function to check the frequency of the words in text files. Make sure to remove any punctuation and convert all words to lower case. If my text file is like this: Hello, This is Python Program? thAt chEcks% THE freQuency of the words! When is printed it should look like this: hello 1 this 1 is 1 python 1 program 1 that 1 checks 1 the 2 frequency 1 of 1 words 1
* What does it mean when header files are described as making a program “modular?” What...
* What does it mean when header files are described as making a program “modular?” What are the advantages of this? * You are testing a program that is designed to take in a pair of float values as input. The intended range is from -50.50 to 100.25. What are 10 test cases you would use to test this program, bearing in mind each test case is a set of two numbers? Briefly justify your choices.
Write the header and the implementation files (.h and .cpp separatelu) for a class called Course,...
Write the header and the implementation files (.h and .cpp separatelu) for a class called Course, and a simple program to test it, according to the following specifications:                    Your class has 3 member data: an integer pointer that will be used to create a dynamic variable to represent the number of students, an integer pointer that will be used to create a dynamic array representing students’ ids, and a double pointer that will be used to create a dynamic array...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT