#include <iostream>          
#include <string.h>          
#include <ctype.h>
using namespace std;
void RemoveSpaces(char *str);
void RemoveVowels(char *str);

int main()
{
   
char clear[256];
char cipher[256];
int x,i;
int opt;




  

cout<<"Encryption (1) 0r Decryption (2):"<<endl;
cin>>opt;
cin.ignore();

if(opt==1)
{
    
cout<<" Enter a string(sentence):";
 cin.getline(clear,sizeof(clear)); 
RemoveSpaces(clear);

x = strlen(clear);

for(i=0;i<=x-1;i++)            
{
cipher[i] = clear[i]+3;
}
cipher[x] = '\0';

cout<<" Encrypted:"<< cipher << endl;


}
for(i=0; i<=x-1; i++)
{                                 
    if (isspace(clear[i]))
    {
        cipher[i] = clear[i];
    }
    else
    {
       cipher[i] = clear[i]+3;
    }
    
cout<<cipher[i]<<endl;
RemoveVowels(clear);





}
 

cin.get();

return 0;

}




  void RemoveSpaces(char *str)
{
   int i = 0;
   int length = strlen(str);
   while(i < length)
   {
      if( isspace(str[i] ))
      {
         memmove(&str[i], &str[i+1], length-1);
         --length;
      }
      else
          ++i;
          
   
           
   }

 
}  


 void RemoveVowels(char *str)
 { 
     int i = 0;
     int  lenght = strlen(str);
     
     for(i=0;i<=-lenght;i++)
     {
              if (str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u' || str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U') {
str[i]=' '; 
      
        
      }  
      }
      
                             //removing Vowels
     
     
     
}

Hey guys I'm trying to remove vowels from a string from inside the function. i just cant figure it out. any advice and tips are very welcome.thanks again

You for loop condition is wrong i<=-lenght the - sign means that for a string with at least 1 character the loop never runs because 0 is greater than all negative numbers. Also remember that C++ indexes start at 0 so if an array has 4 entries its valid indexes are 0, 1, 2, 3.

In light of these your loop condition should be i < lenght .

Finally lenght is spelt length

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.