First time here on StackOverflow. While studying and coding for my final exams at programming, I found a problem that I can mentally resolve, but when I try to put it in C++, it doesn't really work.
So the problem is in my native language, romanian, but i will try to translate it. So the problem wants me to read a word from keyboard and then to show it on the screen, eliminating a vowel each time. For example, if i enter in my program the word "programming" it should show:
- progrmming - eliminating a
- programming - eliminating e
- programmng - eliminating i
- prgramming - eliminating o
- programming - eliminating u
My code looks like this:
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char v[6]="aeiou",s1[21],s2[21];
int i,j;
cin.get(s1,20);
for(i=0;i<strlen(v);i++)
{
strcpy(s2,s1);
j=0;
while(j<strlen(s2))
{
if(strchr(v[i],s2[j])!='\0')
strcpy(s2+j,s2+j+1);
else
j++;
}
cout<<s2<<endl;
}
return 0;
I have a error at the "if" statement, but i can't seem to find a fix for it. It works after i remove the "[i]" from "v[i]", but i need to eliminate only one vowel at a time, not all of them. Hopefully, someone can help me here. Thank you!
EDIT: Problem solved, i will let my code here, because the problem is taken from subjects of romanian baccalaureate at programming
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char v[6]="aeiou",s1[21],s2[21];
int i,j,x;
cin.get(s1,20);
for(i=0;i<strlen(v);i++)
{
strcpy(s2,s1);
j=0;
while(j<strlen(s2))
{
if(s2[j]==v[i])
strcpy(s2+j,s2+j+1);
else
j++;
}
cout<<endl;
cout<<s2<<endl;
}
return 0;
}
Sorry for the misunderstanding, but here, we are not taught to use things like std::string::find_first_of
, just basic funtions like strcmp
and stchr
.