Hey guys--
I have been lurking on here for some time as a C++ student. I have a project to complete using cstring and strcpy() as a function within a "simple" program. The psedocode goes as follows:
--program accepts 2 string array inputs(using getline) 40 total chars for str1 and 20 for str2(added 1 to take in consideration the null char).
--the second array or single character(whichever it may be) has to be removed from the first array and move the null char forward.
--i understand that i have to copy each char into the first array to a location +1 from the current indexed location i am just lost on how to do it.
--it is just whenever i use strcpy(str1, str2);--the second array just replaces the whole first array. how can i replace this char individually even when i put in a string of numbers into str2?
--I am also having problems with the loop. when i prompt the question to try again and enter y/Y, it starts over as expected but puts the 2 cout prompts back to back and only accepts prompt for str2.
--i will post code to let you all see. i am a complete newb to programming. i searched the threads first. just looking for a little hand to get a hint on how to instate this couple of problems. thanks for any help! not asking for anyone to do my homework. just getting understanding before a final comes. here is the code:
# include <iostream>
# include <cstring>
using namespace std;
int main()
{
char str1[41];
char str2[21];
char ans;
do
{
cout<<"Please enter a string (40 characters max)-->";
cin.getline(str1, 41);
cout<<"Please enter the characters to be removed(20 characters max) -->";
cin.getline(str2, 21);
strcpy(str1, str2);
cout<<"First string with characters removed-->"<<str1<<endl;
cout<<"Would you like to do another(y or n)?";
cin>>ans;
}while (ans!='n'||ans!='N');
return 0;
}