Tuesday 24 June 2014

C++ program to trim a string


Here is a C++ program to trim a string


 SOURCE CODE OUTPUT
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char str[100],temp;
    int y,lenght,start,last;
    cout<<"Enter string : ";
    cin>>str;
    cout<<"Enter start and end point : ";
    cin>>start>>last;
    lenght=strlen(str)+start-last-1;
    for(y=last;str[y]!='\0';y++,start++)
        str[start-1]=str[y];
        str[lenght]='\0';
    cout<<"After trimming : "<<str;
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment