A
arnuld
i have created solution which compiles and runs without any error/
warning but it does not work. i am not able to understand why. i
thought it is good to post my code here for correction before looking
at CLC-Wiki for K&R2 solutions:
--------------- PROGRAMME ------------
/* K&R2 section 1.5.3, exercise 1-9
STATEMENT:
write a programme to copy its input to output replacing
each string of 1 or more blanks with single blank.
*/
#include <stdio.h>
int main()
{
int c;
int scount = 0;
while((c = getchar()) != EOF)
{
if(c == ' ')
{
if(scount != 0)
scount = scount + 1;
if(scount == 0)
putchar(c);
}
if(c != ' ')
{
putchar(c);
scount = 0;
}
}
return 0;
}
-------------- OUTPUT ----------------
[arch@voodo kr2]$ gcc -std=c99 -pedantic -Wall -Wextra ex_1-9.c
[arch@voodo kr2]$ ./a.out
like
like
and
and
and this
and this
and this
and this
[arch@voodo kr2]$
warning but it does not work. i am not able to understand why. i
thought it is good to post my code here for correction before looking
at CLC-Wiki for K&R2 solutions:
--------------- PROGRAMME ------------
/* K&R2 section 1.5.3, exercise 1-9
STATEMENT:
write a programme to copy its input to output replacing
each string of 1 or more blanks with single blank.
*/
#include <stdio.h>
int main()
{
int c;
int scount = 0;
while((c = getchar()) != EOF)
{
if(c == ' ')
{
if(scount != 0)
scount = scount + 1;
if(scount == 0)
putchar(c);
}
if(c != ' ')
{
putchar(c);
scount = 0;
}
}
return 0;
}
-------------- OUTPUT ----------------
[arch@voodo kr2]$ gcc -std=c99 -pedantic -Wall -Wextra ex_1-9.c
[arch@voodo kr2]$ ./a.out
like
like
and
and
and this
and this
and this
and this
[arch@voodo kr2]$