PLAY WITH CODING

Home Basic Program If & Else Loops Conversion Pattern logo

Program Based on If & Else

Program to remove spacal character from string

Input - Output

Input
Enter a string : playwithcoding@gmail.com

Output
After removing special character: playwithcodinggmailcom

Algorithm

Step 1: START

Step 2: Enter a string as an input.

Step 3: Check each character of the string:

    if(str[i]>='A' && str[i]<='Z'||str[i]>='a' && str[i]<='z'|| str[i]==' ')

       print str[i];

    else

       print continue;

Step 5: END

CODE


/* remove special character from string */
#include <stdio.h>
#include <string.h>
int main()
{
      char str[30];
      printf(" Enter a string: ");
      gets(str);
      printf("After removing special character from string : ");
      for(int i=0;str[i];i++)
     {
          if(str[i]>='A' && str[i]<='Z'||str[i]>='a' && str[i]<='z'|| str[i]==' ')
             printf("%c",str[i]);
          else
                continue;
     }
    return 0;
}


/* remove special character from string */
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
      char str[30];
      cout<<" Enter a string: ";
      gets(str);
      cout<<"After removing special character from string : ";
      for(int i=0;str[i];i++)
     {
          if(str[i]>='A' && str[i]<='Z'||str[i]>='a' && str[i]<='z'|| str[i]==' ')
            cout<<str[i];
          else
                continue;
     }
    return 0;
}

OutPut

Enter a string : playwithcoding@gmail.com

After removing special character: playwithcodinggmailcom