Question
need help on c++ program please. // SmpCStrings.cpp // Kim Buckner // COSC1030, Sp 2017 // Lecture 19 // Playing with null-terminated C-strings. #include using
need help on c++ program please.
// SmpCStrings.cpp // Kim Buckner // COSC1030, Sp 2017 // Lecture 19 // Playing with null-terminated C-strings.
#include
#include
int main() { char message1[]="Howdy";
cout
char *msgPtr; msgPtr = message1; // Try to compile and run without this line! cout
char message2[]="Here's a much longer message."; cout
msgPtr = message2; cout
char message3[]={'H','e','r','e',' ','w','e',' ','g','o'}; cout
msgPtr = message3; cout
msgPtr = new char[56]; for(int i=0;i
cout
cout > buffer; len=strlen(buffer); cout
return 0; }
Procedure Now we will write a simple program that will interact with the user. You will prompt the user for various inputs. You will read in strings and lines. Then you will report some information on them and modify them. 1. Construct a new Microsoft Visual Studio Win32 Console Application project for Lab 11 2. I suggest that you refer to the file SmpCStrings.cpp from Lecture 19. You will need to read strings in from the user into a buffer (an array that is used to "buffer" data between the program and external devices). That file has examples of the some the things you will need to do. 3. Prompt the user for a string, read it in, and "echo it back out one character at a time, treating the string buffer as a simple array 4. Prompt the user for sentence (less than 256 characters long) Read in the entire sentence as a single string. You will need the cin.getline0 function to do this; this function is slightly different from the std: getline. You need to do a little research on how to use it. Now report the length of the string (use strlen() to get that). Also report on what the cin.gcount0 function returned. There is problem here. That new line that the user typed in the last time, is still in the stream. So that means this will immediately return with a 0 length string. So, just BEFORE you prompt the user for the sentence, use cin.getline() to read in whatever is left in the stream, and just ignore it. Here you can use the same buffer and just not worry about whatever is in it. Everytime you use cin.getline0 it will overwrite the storage with the new data. 5. Prompt the user to enter an integer. You will use that number to shorten the string. That means that you are going to change the character stored in that position in the buffer. BUT, before you change that character (to 0) you need to save the original character. Because after you print out the modified string, you will restore the removed character and print out the original stringStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started