Re: HELP!! Two questions from <<the c programming language>>
- From: Guru Jois <guru.jois@xxxxxxxxx>
- Date: 31 May 2007 09:10:18 -0700
On May 31, 3:27 pm, Tak <kakat...@xxxxxxxxx> wrote:
Algorithm trim_space
while EOF
do
begin
input char
if char = space then
begin
if flag = 0 then
begin
let flag = 1;
print char;
end
end
else
begin
let flag = 0
print char
end
end
goto step 2
end while
My program of exercise 1-9
#include <stdio.h>
int main()
{
int flag=1;
int c;
while ((c = getchar()) != EOF)
{
if (c == ' ')
{
flag = 0;
}
else if (flag == 0)
{
printf(" ");
putchar(c);
flag = 1;
}
else
putchar(c);
}
}
It seems run OK,without error or warning in Vc++6.0.
Does it still contain any problems?
yet smaller code..
#include<stdio.h>
main() {
int c;
int flag;
flag = 0;
while ((c = getchar ()) != EOF) {
if (c == ' ') {
if (!flag) {
flag = 1;
putchar (c);
}
}
else {
flag = 0;
putchar (c);
}
}
}
Bye
Guru Jois
.
- References:
- HELP!! Two questions from <<the c programming language>>
- From: Tak
- Re: HELP!! Two questions from <<the c programming language>>
- From: Ian Collins
- Re: HELP!! Two questions from <<the c programming language>>
- From: Tak
- Re: HELP!! Two questions from <<the c programming language>>
- From: Guru Jois
- Re: HELP!! Two questions from <<the c programming language>>
- From: Tak
- HELP!! Two questions from <<the c programming language>>
- Prev by Date: Re: HELP!! Two questions from <<the c programming language>>
- Next by Date: Re: global variable declaration in header
- Previous by thread: Re: HELP!! Two questions from <<the c programming language>>
- Next by thread: Re: HELP!! Two questions from <<the c programming language>>
- Index(es):
Relevant Pages
|