on Saturday, 13 April 2013

/* Remove white space with sign */


#include<stdio.h>
void remove_white_space(char *source) {  // including first sign(+/-) if exist
int iffc=0; //iffc=index_find_first_character after first sign
int ic=0; // index copy

/* find first character */
while(source[iffc]!='\0'){

if(source[iffc]==' '){ // seek for space
iffc++;
continue;
}

if(source[iffc]=='+' || source[iffc]=='-'){
iffc++;
break;
}

break;
}

if(iffc==0) // no whitespace found
return;


/* copy string part onto white space */


while(source[iffc]!='\0'){
source[ic]=source[iffc];
printf("%c",source[ic]);
ic++;
iffc++;

}
source[ic]='\0'; // insert null at the end of string

 }



void main(){
char source[]="palash";  // can supply any input
printf("%s",source);
remove_white_space(source);
printf("\n%s",source);


}

0 comments:

Post a Comment