A
arnuld
it works fine. any advice for improvement:
---------- PROGRAMME --------------
/* K&R2: section 1.5.3, exercise 1-9
STATEMENT:
write a programme to copy its input to its output
replacing a string of one more blanks with a single blank.
*/
#include<stdio.h>
#define IN 1
#define OUT 0
int main()
{
int c = 0;
int state = OUT;
while((c = getchar()) != EOF)
{
if(c == ' ')
{
if(state == OUT)
{
state = IN;
putchar(c);
}
}
if(c != ' ')
{
putchar(c);
state = OUT;
}
}
return 0;
}
------------- OUTPUT ------------
[arch@voodo kr2]$ gcc -ansi -pedantic -Wall -Wextra ex_1-9.c
[arch@voodo kr2]$ ./a.out
like this
like this
like this
like this
like this
like this
like this
like this
like this
like this
[arch@voodo kr2]$
---------- PROGRAMME --------------
/* K&R2: section 1.5.3, exercise 1-9
STATEMENT:
write a programme to copy its input to its output
replacing a string of one more blanks with a single blank.
*/
#include<stdio.h>
#define IN 1
#define OUT 0
int main()
{
int c = 0;
int state = OUT;
while((c = getchar()) != EOF)
{
if(c == ' ')
{
if(state == OUT)
{
state = IN;
putchar(c);
}
}
if(c != ' ')
{
putchar(c);
state = OUT;
}
}
return 0;
}
------------- OUTPUT ------------
[arch@voodo kr2]$ gcc -ansi -pedantic -Wall -Wextra ex_1-9.c
[arch@voodo kr2]$ ./a.out
like this
like this
like this
like this
like this
like this
like this
like this
like this
like this
[arch@voodo kr2]$