Tuesday 24 June 2014

C++ program to delete white spaces from string


Here is a C++ Write a C++ program to delete white spaces from string


 SOURCE CODE OUTPUT
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char str[100];
    cout<<"Enter string : ";
    cin.getline(str,100);
    for(int i=0;str[i]!='\0';i++)
    {
        if(str[i]==' ')
            for(int y=i;str[y]!='\0';y++)
                  str[y]=str[y+1];
    }
    cout<<"After removing white spaces : "<<str;
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment