#include <iostream>
#include <string.h>
#include <ctype.h>
using namespace std;

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


cout<<" Enter a string:";
cin.getline(clear,sizeof(clear));

x = strlen(clear);

for(i=0;i<=x-1;i++)

{
cipher[i] = clear[i]+3;
}
cipher[x] = '\0';
cout<<" Encrypted:" << cipher << endl;



system("pause");

return 0;
}
Hey Guy i'm new to C++ programming i have a program to encrypt a string(sentence), i need to use a function but dont know how to go about implementing it. after i encrypt the sentence i want to remove the space from it, and then use another function for removing the vowels. can i use this code in the function for removing spaces.
for(i=0;i<=x-1;i++)

{
if(cipher[i]!=' ')
{
cout<<cipher[i]<< endl;         // removing spaces from string(sentence)
}

thanks in advanced guys hope you can help.

That removes the spaces from the display of cipher but not from cipher itself.

BTW: Please use code tags to enclose any code you post to maintain the formatting you (hopefully) use when writing your code. It is a bit of a hassle if you've never done it before. But if you don't, many of the premiere responders won't bother to read/respond to your post.

#include <iostream>
#include <string.h>
#include <ctype.h>
using namespace std;

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


cout<<" Enter a string:";
cin.getline(clear,sizeof(clear));

x = strlen(clear);

for(i=0;i<=x-1;i++)

{
cipher[i] = clear[i]+3;
}
cipher[x] = '\0';
cout<<" Encrypted:" << cipher << endl;



system("pause");

return 0;
}

sorry about the that never knew about the code tags cheers for the input.

#include <iostream>
#include <string.h>
#include <ctype.h>
using namespace std;

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


cout<<" Enter a string:";
cin.getline(clear,sizeof(clear));

x = strlen(clear);

for(i=0;i<=x-1;i++)

{
cipher[i] = clear[i]+3;
}
cipher[x] = '\0';
cout<<" Encrypted:" << cipher << endl;



system("pause");

return 0;
}

sorry about the that never knew about the code tags cheers for the input.

hey Guys i truly need some help with calling the function outside of the program above to remove the spaces from the string. any tip would be much appreciated thanks again.

hey Guys i truly need some help with calling the function outside of the program above to remove the spaces from the string. any tip would be much appreciated thanks again.

Hey,

Here is example that I found on how to check for letters, words, spaces, digits, and punctuations in a string => URL Snipped

and here is how to remove white space

s.erase(remove_if(s.begin(), s.end(), isspace), s.end());

or

for(int i=0; i<str.length(); i++)
     if(str[i] == ' ') str.erase(i,1);

And the only thing you need to do is to put together.

I hope this help you, good luck.

#include <iostream>
#include <string.h>

using namespace std;
class Functions
{
public:
   Functions()
  {

    char str[100];
    cout<<"Enter the String:";
    cin.getline(str,sizeof(str));
    
    char newstr[100]={NULL};
    for (int i=0,j=0;i<strlen(str);i++)
    {
      if(str[i] == ' ')
      {
        
      }
      else
      {
       newstr[j] = str[i];
       j++;
       }
    }

    cout<<"New String:"<<newstr<<endl;

  }

};


int main()
{

 Functions();
 
 return 0;
}

You can use Peter's method, but if you dont intend to use built in functions, or you would like to stick to basic programming, this code might help you.

thanks peter.

Thank alot for the input

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.