Operating System - HP-UX
1833940 Members
1645 Online
110063 Solutions
New Discussion

How to suppress space characters - C-ANSIC program

 
LEJARRE Patrick
Advisor

How to suppress space characters - C-ANSIC program

hi,
I need a simple C-ANSIC program to suppress spaces from strings.
Can anyone help me ?

string_in => ' this is my line '
shoudl be converted in
string_out => 'thisismyline'

thanks in advance
1 REPLY 1
Jean-Luc Oudart
Honored Contributor

Re: How to suppress space characters - C-ANSIC program

If this was a script this could be done so quickly ...

not the best at C but try this

#include
#include

main (argc,argv)
char **argv;
int argc;
{
int i;
size_t len;
len=strlen(argv[1]);
for(i=0; i < len ; i++) {
/* if(argv[1][i]!=' ') printf("%c",argv[1][i]); */
if(argv[1][i]!=' ') putchar(argv[1][i]);
}
printf("\n");
}

Rgds,
Jean-Luc
fiat lux