473,503 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

program bug

I have looked this program up and down and I don't see what's wrong with
it. But it always breaks and gives me an error "mode error" no matter which
mode binary or text I choose. This simple program is supposed to take as
argv[1] a "b" or "t" for binary or text. It's not taking anything.

#include <stdio.h>

int main(int argc, char **argv) {
char *b;
int a;
FILE *ifp,*ofp;
if (argc!=4) {
fprintf(stderr,"usage error\n");
return -1;
}
if (argv[1]=="b") {
b="rb";
}
if (argv[1]=="t") {
b="rt";
}
if (argv[1]!="t"||argv[1]!="b") {
fprintf(stderr,"mode error\n");
return -1;
}
if ((ifp=fopen(argv[2],b))==0) {
fprintf(stderr,"open error i\n");
return -1;
}
if ((ofp=fopen(argv[3],b))==0) {
fprintf(stderr,"open error o\n");
return -1;
}
while(a!=EOF)
a=fgetc(ifp);
fputc(a,ofp);
printf("done\n");
return 0;}

Is anyone good enough to glance at this and see what's wrong?

Bill
Jun 27 '08 #1
35 1179
Well I now see I left out fclose I will correct that but I don't think
that's my problem.

Bill
Jun 27 '08 #2
On May 2, 5:40 pm, "Bill Cunningham" <nos...@nspam.comwrote:
I have looked this program up and down and I don't see what's wrong with
it. But it always breaks and gives me an error "mode error" no matter which
mode binary or text I choose. This simple program is supposed to take as
argv[1] a "b" or "t" for binary or text. It's not taking anything.

#include <stdio.h>

int main(int argc, char **argv) {
char *b;
int a;
FILE *ifp,*ofp;
if (argc!=4) {
fprintf(stderr,"usage error\n");
return -1;
Not a portable return value from main.
}
if (argv[1]=="b") {
This isn't doing what you think it is. This is comparing the address
of first program argument to the address of the string literal "b"
which will always be different. Either use (strcmp(argv[1], "b") ==
0) or say:

if (argv[1][0] == 'b') {

which will compare the first letter of the first argument to the
character constant b.
b="rb";
}
if (argv[1]=="t") {
b="rt";
}
if (argv[1]!="t"||argv[1]!="b") {
fprintf(stderr,"mode error\n");
return -1;
}
if ((ifp=fopen(argv[2],b))==0) {
fprintf(stderr,"open error i\n");
return -1;
}
if ((ofp=fopen(argv[3],b))==0) {
fprintf(stderr,"open error o\n");
return -1;
}
while(a!=EOF)
a is not initialized, referencing its value invokes undefined
behavior.
a=fgetc(ifp);
fputc(a,ofp);
I think you want braces around these statements, yes?

Try (not tested):

while ( (a = fgetc(ifp)) != EOF && fputc(a, ofp) != EOF )
;
printf("done\n");
puts("done"); would work equally well.
return 0;}

Is anyone good enough to glance at this and see what's wrong?

Bill
--
Robert Gamble
Jun 27 '08 #3
On May 2, 5:53 pm, "Bill Cunningham" <nos...@nspam.comwrote:
Well I now see I left out fclose I will correct that but I don't think
that's my problem.

Bill
There were a number of problems with the program but as long as the
program was terminating normally the fclose() wasn't one of them, all
files are properly closed during normal program termination (although
it is usually a good idea to explicitly close files yourself).

--
Robert Gamble
Jun 27 '08 #4

"Robert Gamble" <rg*******@gmail.comwrote in message
news:2d**********************************@8g2000hs e.googlegroups.com...
>a is not initialized, referencing its value invokes undefined
behavior.
> a=fgetc(ifp);
fputc(a,ofp);
In the beginning a was declared. Is it not enough in this case to simply
declare an int? Or should I have done this int a=0; at the beginning of the
program?

Bill
Jun 27 '08 #5

"Robert Gamble" <rg*******@gmail.comwrote in message
news:2d**********************************@8g2000hs e.googlegroups.com...
Not a portable return value from main.
> }
if (argv[1]=="b") {

This isn't doing what you think it is. This is comparing the address
of first program argument to the address of the string literal "b"
Was declaring b as a pointer to char proper? Or should a simple b of
type char all that's needed?

which will always be different. Either use (strcmp(argv[1], "b") ==
0) or say:

if (argv[1][0] == 'b') {

which will compare the first letter of the first argument to the
character constant b.
I do not understand the above but it looks like a good way to write
code. Why is a zero used as the second dimension of this array?

Bill

Jun 27 '08 #6
Bill Cunningham wrote:
I have looked this program up and down and I don't see what's wrong with
it. But it always breaks and gives me an error "mode error" no matter which
mode binary or text I choose. This simple program is supposed to take as
argv[1] a "b" or "t" for binary or text. It's not taking anything.

#include <stdio.h>

int main(int argc, char **argv) {
char *b;
int a;
FILE *ifp,*ofp;
if (argc!=4) {
fprintf(stderr,"usage error\n");
return -1;
}
if (argv[1]=="b") {
b="rb";
}
if (argv[1]=="t") {
b="rt";
}
if (argv[1]!="t"||argv[1]!="b") {
fprintf(stderr,"mode error\n");
return -1;
}
if ((ifp=fopen(argv[2],b))==0) {
fprintf(stderr,"open error i\n");
return -1;
}
if ((ofp=fopen(argv[3],b))==0) {
fprintf(stderr,"open error o\n");
return -1;
}
while(a!=EOF)
a=fgetc(ifp);
fputc(a,ofp);
printf("done\n");
return 0;}

Is anyone good enough to glance at this and see what's wrong?

Bill

You can't use == to compare strings. That's what strcmp() is for. This
is the first error I find, not the only one.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Jun 27 '08 #7
On May 2, 6:16 pm, "Bill Cunningham" <nos...@nspam.comwrote:
"Robert Gamble" <rgambl...@gmail.comwrote in message

news:2d**********************************@8g2000hs e.googlegroups.com...
a is not initialized, referencing its value invokes undefined
behavior.
a=fgetc(ifp);
fputc(a,ofp);

In the beginning a was declared. Is it not enough in this case to simply
declare an int? Or should I have done this int a=0; at the beginning of the
program?
You need to store a value into a variable before you use the value of
that variable, either through initialization (implicit or explicit) or
assignment. If you don't do this then the variable may contain
garbage ("indeterminate value" in standards parlance), that garbage
may be a trap value which will invoke UB when read. Note that the
alternative I provided does not have this problem because "a" is
assigned before its value is used.

--
Robert Gamble
Jun 27 '08 #8
Bill Cunningham wrote:
I have looked this program up and down and I don't see what's wrong with
it. But it always breaks and gives me an error "mode error" no matter which
mode binary or text I choose. This simple program is supposed to take as
argv[1] a "b" or "t" for binary or text. It's not taking anything.

#include <stdio.h>

int main(int argc, char **argv) {
char *b;
int a;
FILE *ifp,*ofp;
if (argc!=4) {
fprintf(stderr,"usage error\n");
return -1;
}
if (argv[1]=="b") {
b="rb";
}
if (argv[1]=="t") {
b="rt";
}
if (argv[1]!="t"||argv[1]!="b") {
fprintf(stderr,"mode error\n");
return -1;
}
if ((ifp=fopen(argv[2],b))==0) {
fprintf(stderr,"open error i\n");
return -1;
}
if ((ofp=fopen(argv[3],b))==0) {
fprintf(stderr,"open error o\n");
return -1;
}
while(a!=EOF)
a=fgetc(ifp);
fputc(a,ofp);
printf("done\n");
return 0;}

Is anyone good enough to glance at this and see what's wrong?
Someone stole the whitespace?

Why are you comparing characters with string literals? Surly your
compiler gave you some warnings?

--
Ian Collins.
Jun 27 '08 #9

"Ian Collins" <ia******@hotmail.comwrote in message
news:68**************@mid.individual.net...
Why are you comparing characters with string literals? Surly your
compiler gave you some warnings?
Not as whisper. As it is typed as is.

Bill
Jun 27 '08 #10
On May 2, 6:28 pm, Ian Collins <ian-n...@hotmail.comwrote:
Bill Cunningham wrote:
I have looked this program up and down and I don't see what's wrong with
it. But it always breaks and gives me an error "mode error" no matter which
mode binary or text I choose. This simple program is supposed to take as
argv[1] a "b" or "t" for binary or text. It's not taking anything.
#include <stdio.h>
int main(int argc, char **argv) {
char *b;
int a;
FILE *ifp,*ofp;
if (argc!=4) {
fprintf(stderr,"usage error\n");
return -1;
}
if (argv[1]=="b") {
b="rb";
}
if (argv[1]=="t") {
b="rt";
}
if (argv[1]!="t"||argv[1]!="b") {
fprintf(stderr,"mode error\n");
return -1;
}
if ((ifp=fopen(argv[2],b))==0) {
fprintf(stderr,"open error i\n");
return -1;
}
if ((ofp=fopen(argv[3],b))==0) {
fprintf(stderr,"open error o\n");
return -1;
}
while(a!=EOF)
a=fgetc(ifp);
fputc(a,ofp);
printf("done\n");
return 0;}
Is anyone good enough to glance at this and see what's wrong?

Someone stole the whitespace?

Why are you comparing characters with string literals? Surly your
compiler gave you some warnings?
My compiler didn't provide any warnings for this code, did yours?

--
Robert Gamble
Jun 27 '08 #11

"Ian Collins" <ia******@hotmail.comwrote in message
news:68**************@mid.individual.net...
Someone stole the whitespace?
I was always told there were several choices in C indentation. These two
and maybe a third.

function { /*notice the one space after the first brace*/
} closing brace on a line by itself.
This is the style I use and another

function
{

body

}

With this style all braces are on lines by themselves.
Bill
Jun 27 '08 #12
Ian Collins wrote:
>
.... snip ...
>
Someone stole the whitespace?

Why are you comparing characters with string literals? Surly
your compiler gave you some warnings?
Surly compilers have that fault. :-)

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

** Posted from http://www.teranews.com **
Jun 27 '08 #13
Bill Cunningham wrote:
"Robert Gamble" <rg*******@gmail.comwrote in message
>a is not initialized, referencing its value invokes undefined
behavior.

a=fgetc(ifp);
fputc(a,ofp);

In the beginning a was declared. Is it not enough in this case to
simply declare an int? Or should I have done this int a=0; at the
beginning of the program?
You are using it before loading it. You want:

while (EOF != (a = fgetc(ifp))) fputc(a, ofp);

Note the use of blanks. As I recall there are other errors also.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #14
Robert Gamble wrote:
On May 2, 6:28 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>
Why are you comparing characters with string literals? Surly your
compiler gave you some warnings?

My compiler didn't provide any warnings for this code, did yours?
Oops, my bad, I spotted the comparisons an didn't spot they were with
argv[n].

--
Ian Collins.
Jun 27 '08 #15
Ian Collins wrote:
Robert Gamble wrote:
>On May 2, 6:28 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>Why are you comparing characters with string literals? Surly your
compiler gave you some warnings?
My compiler didn't provide any warnings for this code, did yours?
Oops, my bad, I spotted the comparisons an didn't spot they were with
argv[n].
So what?

if (argv[1] == "b")

is not an error the compiler need diagnose. Both arguments are of type
(char *) and the chances the two pointer values are equal is nil but the
expression is completely valid.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Jun 27 '08 #16
Joe Wright wrote:
Ian Collins wrote:
>Robert Gamble wrote:
>>On May 2, 6:28 pm, Ian Collins <ian-n...@hotmail.comwrote:
Why are you comparing characters with string literals? Surly your
compiler gave you some warnings?
My compiler didn't provide any warnings for this code, did yours?
Oops, my bad, I spotted the comparisons an didn't spot they were with
argv[n].
So what?

if (argv[1] == "b")

is not an error the compiler need diagnose. Both arguments are of type
(char *) and the chances the two pointer values are equal is nil but the
expression is completely valid.
I know, that's why I said I didn't spot the comparison was with argv[n].
If I had, I wouldn't have mentioned compiler warnings.

--
Ian Collins.
Jun 27 '08 #17
On May 2, 2:40*pm, "Bill Cunningham" <nos...@nspam.comwrote:
* * I have looked this program up and down and I don't see what's wrong with
it. But it always breaks and gives me an error "mode error" no matter which
mode binary or text I choose. This simple program is supposed to take as
argv[1] a "b" or "t" for binary or text. It's not taking anything.

#include <stdio.h>

int main(int argc, char **argv) {
*char *b;
*int a;
*FILE *ifp,*ofp;
*if (argc!=4) {
*fprintf(stderr,"usage error\n");
*return -1;
*}
*if (argv[1]=="b") {
*b="rb";
*}
*if (argv[1]=="t") {
*b="rt";
*}
*if (argv[1]!="t"||argv[1]!="b") {
*fprintf(stderr,"mode error\n");
*return -1;
*}
*if ((ifp=fopen(argv[2],b))==0) {
*fprintf(stderr,"open error i\n");
*return -1;
*}
*if ((ofp=fopen(argv[3],b))==0) {
*fprintf(stderr,"open error o\n");
*return -1;
*}
*while(a!=EOF)
*a=fgetc(ifp);
*fputc(a,ofp);
*printf("done\n");
*return 0;}

* * Is anyone good enough to glance at this and see what's wrong?
Too many things for a glance. It requires a perusal.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
char *imode = 0;
char *omode = 0;
char option;
int ch = 0;

FILE *ifp,
*ofp;
if (argc != 4) {
fprintf(stderr, "usage error\n");
return EXIT_FAILURE;
}
option = *argv[1];
if (option == 'b') {
imode = "rb";
omode = "wb";
}
if (option == 't') {
/* This may or may not do something useful on your system */
/* The 't' in the mode is not portable, but is a fairly */
/* popular extension for text mode. */
imode = "rt";
omode = "wt";
}
if (option != 't' && option != 'b') {
fprintf(stderr, "mode error\n");
return EXIT_FAILURE;
}
if ((ifp = fopen(argv[2], imode)) == 0) {
fprintf(stderr, "open error i\n");
return EXIT_FAILURE;
}
if ((ofp = fopen(argv[3], omode)) == 0) {
fprintf(stderr, "open error o\n");
return EXIT_FAILURE;
}
/* I guess that you want to write what you read, hence the {} */
do {
ch = fgetc(ifp);
if (ch != EOF)
fputc(ch, ofp);
} while (ch != EOF);
fclose(ifp);
fclose(ofp);
printf("done\n");
return 0;
}
Jun 27 '08 #18
"Bill Cunningham" <no****@nspam.comwrites:
"Ian Collins" <ia******@hotmail.comwrote in message
news:68**************@mid.individual.net...
>Someone stole the whitespace?

I was always told there were several choices in C indentation.
[...]

Yes, there are serveral choices. No indentation at all is not one of
them.

If you want help with your code, indent it. It doesn't matter much
which indentation style you choose, but pick *something* that reflects
the structure of your code. (To be clear, indentation refers to
whitespace at the beginning of each line.)

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #19
Keith Thompson said:
"Bill Cunningham" <no****@nspam.comwrites:
>"Ian Collins" <ia******@hotmail.comwrote in message
news:68**************@mid.individual.net...
>>Someone stole the whitespace?

I was always told there were several choices in C indentation.
[...]

Yes, there are serveral choices. No indentation at all is not one of
them.
Wrong. No indentation at all *is* a valid choice. The OP is under no
obligation whatsoever to write his code in a way that encourages people to
help him.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #20

"user923005" <dc*****@connx.comwrote in message
news:6f**********************************@i76g2000 hsf.googlegroups.com...
#include <stdio.h>

int main(int argc, char **argv) {
char *b;
int a;
FILE *ifp,*ofp;
if (argc!=4) {
fprintf(stderr,"usage error\n");
return -1;
}
if (argv[1]=="b") {
b="rb";
}
if (argv[1]=="t") {
b="rt";
}
if (argv[1]!="t"||argv[1]!="b") {
fprintf(stderr,"mode error\n");
return -1;
}
if ((ifp=fopen(argv[2],b))==0) {
fprintf(stderr,"open error i\n");
return -1;
}
if ((ofp=fopen(argv[3],b))==0) {
fprintf(stderr,"open error o\n");
return -1;
}
while(a!=EOF)
a=fgetc(ifp);
fputc(a,ofp);
printf("done\n");
return 0;}

Is anyone good enough to glance at this and see what's wrong?
Too many things for a glance. It requires a perusal.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
char *imode = 0;
char *omode = 0;
char option;
int ch = 0;

FILE *ifp,
*ofp;
if (argc != 4) {
fprintf(stderr, "usage error\n");
return EXIT_FAILURE;
}
option = *argv[1];
if (option == 'b') {
imode = "rb";
omode = "wb";
}
if (option == 't') {
/* This may or may not do something useful on your system */
/* The 't' in the mode is not portable, but is a fairly */
/* popular extension for text mode. */
imode = "rt";
omode = "wt";
}
if (option != 't' && option != 'b') {
fprintf(stderr, "mode error\n");
return EXIT_FAILURE;
}
if ((ifp = fopen(argv[2], imode)) == 0) {
fprintf(stderr, "open error i\n");
return EXIT_FAILURE;
}
if ((ofp = fopen(argv[3], omode)) == 0) {
fprintf(stderr, "open error o\n");
return EXIT_FAILURE;
}
/* I guess that you want to write what you read, hence the {} */
do {
ch = fgetc(ifp);
if (ch != EOF)
fputc(ch, ofp);
} while (ch != EOF);
fclose(ifp);
fclose(ofp);
printf("done\n");
return 0;
}

I will definately save this code and study it. I really do no use do so
maybe this will open my eyes to it some.

Bill
Jun 27 '08 #21
On May 3, 6:52 pm, "Bill Cunningham" <nos...@nspam.comwrote:
"user923005" <dcor...@connx.comwrote in message

news:6f**********************************@i76g2000 hsf.googlegroups.com...
#include <stdio.h>
int main(int argc, char **argv) {
char *b;
int a;
FILE *ifp,*ofp;
if (argc!=4) {
fprintf(stderr,"usage error\n");
return -1;
}
if (argv[1]=="b") {
b="rb";
}
if (argv[1]=="t") {
b="rt";
}
if (argv[1]!="t"||argv[1]!="b") {
fprintf(stderr,"mode error\n");
return -1;
}
if ((ifp=fopen(argv[2],b))==0) {
fprintf(stderr,"open error i\n");
return -1;
}
if ((ofp=fopen(argv[3],b))==0) {
fprintf(stderr,"open error o\n");
return -1;
}
while(a!=EOF)
a=fgetc(ifp);
fputc(a,ofp);
printf("done\n");
return 0;}
Is anyone good enough to glance at this and see what's wrong?

Too many things for a glance. It requires a perusal.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
char *imode = 0;
char *omode = 0;
char option;
int ch = 0;

FILE *ifp,
*ofp;
if (argc != 4) {
fprintf(stderr, "usage error\n");
return EXIT_FAILURE;
}
option = *argv[1];
if (option == 'b') {
imode = "rb";
omode = "wb";
}
if (option == 't') {
/* This may or may not do something useful on your system */
/* The 't' in the mode is not portable, but is a fairly */
/* popular extension for text mode. */
imode = "rt";
omode = "wt";
Hahah, what else will the troll come up with? You're entertaining, but
it's sad that posters take you seriously.
Jun 27 '08 #22

"Robert Gamble" <rg*******@gmail.comwrote in message
news:2d**********************************@8g2000hs e.googlegroups.com...

[snip]

I think you want braces around these statements, yes?
I don't know. I've ran code before and seen a lot of people use while
and statements after it and the code works. No braces. So I usually use it
like that. It's not a typo I don't usually use braces with while.
Try (not tested):

while ( (a = fgetc(ifp)) != EOF && fputc(a, ofp) != EOF )
;
> printf("done\n");

puts("done"); would work equally well.
> return 0;}

Is anyone good enough to glance at this and see what's wrong?

Bill

--
Robert Gamble

Jun 27 '08 #23
"Bill Cunningham" <no****@nspam.comwrites:
"Robert Gamble" <rg*******@gmail.comwrote in message
news:2d**********************************@8g2000hs e.googlegroups.com...

[snip]

>I think you want braces around these statements, yes?

I don't know. I've ran code before and seen a lot of people use while
and statements after it and the code works. No braces. So I usually use it
like that. It's not a typo I don't usually use braces with while.
[...]

Do you understand what the braces mean?

Here's the tail end of the code Robert was commenting on:

[...]
while(a!=EOF)
a=fgetc(ifp);
fputc(a,ofp);
printf("done\n");
return 0;}

Putting the closing brace immediately after the semicolon like that is
horribly bad style. Putting everything at the same indentation level
is also horribly bad style. The compiler doesn't care, but anyone
trying to read your code does.

The syntax of a while statement is:

while ( expression ) statement

Note that that's a *single* statement. If you want the body to be
multiple statements, you need to wrap them in braces to create a
compound statement, which is itself as single statement. (The same
thing applies to if statements; you correctly used braces for those,
so I don't know why the while loop was such a problem.)

The code I quoted is equivalent to this:

[...]
while (a != EOF)
a = fgetc(ifp);
fputc(a, ofp);
printf("done\n");
return 0;
}

With proper indentation, you can see that the while controls only a
single statement, ``a = fgetc(ifp);''. The fputc call will occur
exactly once, after the while loop terminates. I can't be certain,
but I *think* you wanted both the fgetc and fputc calls to be in the
body of the loop. To do that, you need braces:

[...]
while (a != EOF) {
a = fgetc(ifp);
fputc(a, ofp);
}
printf("done\n");
return 0;
}

In my opinion, it's a good habit always to use braces even if you only
want only a single statement in the body. It makes the code more
consistent and easier to maintain if you later want to add a second
statement. (Others will disagree.)

Judicious use of whitespace, especially around operators and after
commas, also makes the code much easier to read.

From now on, if you post a chunk of nearly illegible code like what
you posted upthread, with no indentation and virtually no whitespace,
I will ask you to format it properly before I'll even consider helping
you fix any other problems.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #24

"Keith Thompson" <ks***@mib.orgwrote in message
news:87************@kvetch.smov.org...
The syntax of a while statement is:

while ( expression ) statement

Note that that's a *single* statement. If you want the body to be
multiple statements, you need to wrap them in braces to create a
compound statement,
I see.

which is itself as single statement. (The same
thing applies to if statements; you correctly used braces for those,
I think braces are required with if.
so I don't know why the while loop was such a problem.)

The code I quoted is equivalent to this:

[...]
while (a != EOF)
a = fgetc(ifp);
fputc(a, ofp);
printf("done\n");
return 0;
}

With proper indentation, you can see that the while controls only a
single statement, ``a = fgetc(ifp);''. The fputc call will occur
exactly once, after the while loop terminates. I can't be certain,
but I *think* you wanted both the fgetc and fputc calls to be in the
body of the loop. To do that, you need braces:

[...]
while (a != EOF) {
a = fgetc(ifp);
fputc(a, ofp);
}
printf("done\n");
return 0;
}

In my opinion, it's a good habit always to use braces even if you only
want only a single statement in the body. It makes the code more
consistent and easier to maintain if you later want to add a second
statement. (Others will disagree.)

Judicious use of whitespace, especially around operators and after
commas, also makes the code much easier to read.

From now on, if you post a chunk of nearly illegible code like what
you posted upthread, with no indentation and virtually no whitespace,
I will ask you to format it properly before I'll even consider helping
you fix any other problems.
OK

Bill
Jun 27 '08 #25
On May 4, 1:58 am, "Bill Cunningham" <nos...@nspam.comwrote:
"Keith Thompson" <ks...@mib.orgwrote in message

news:87************@kvetch.smov.org...
The syntax of a while statement is:
while ( expression ) statement
Note that that's a *single* statement. If you want the body to be
multiple statements, you need to wrap them in braces to create a
compound statement,

I see.

which is itself as single statement. (The same
thing applies to if statements; you correctly used braces for those,

I think braces are required with if.
No they are not. You know it, you could try it, you could read about
it.
*OR* you could just read what mr Keith said; *the* *same* *thing*
*applies* *to* *if* *statements*.
Just once more, just in case:
*the* *same* *thing* *applies* *to* *if* *statements*.
Now, every day you wake up, you should run this commant in your
terminal: 'yes the same thing applies to if statements', until you
memorize it. Then you can chant it quietly, until you understand it.

Mr Keith (and anyone else who actually cared to reply to this troll)
I'm really tired of seeing clc replying to him.
Assuming he is actually not able to learn after so many years, and
assuming he can't understand what he reads in usenet messages (as
shown just now), you are simply not helping him. Just how stupid does
one have to be to say "I think B isn't" when you say "A is, same
applies for B?"
And what's up with all the horrible indentation he comes up with every
single time, the horrible questions "is anyone good enough to [...]"
in his original message, which could simply be answered with
"yes"/"no", the repeating mistakes, the tendency to reply without
quoting, taking quotes out of context (notice his reply to Mr Gamble)

Honestly, I'm tired of these threads. I also think I make a fool of
myself, since such replies most likely entertain him and the other
trolls...
Jun 27 '08 #26
"Bill Cunningham" <no****@nspam.comwrites:
"Keith Thompson" <ks***@mib.orgwrote in message
news:87************@kvetch.smov.org...
>The syntax of a while statement is:

while ( expression ) statement

Note that that's a *single* statement. If you want the body to be
multiple statements, you need to wrap them in braces to create a
compound statement,

I see.

which is itself as single statement. (The same
>thing applies to if statements; you correctly used braces for those,

I think braces are required with if.
[...]

You're guessing. Don't guess. Look it up.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #27
vi******@gmail.com wrote:
>
.... snip ...
>
Mr Keith (and anyone else who actually cared to reply to this
troll) I'm really tired of seeing clc replying to him. Assuming
he is actually not able to learn after so many years, and assuming
he can't understand what he reads in usenet messages (as shown
just now), you are simply not helping him. Just how stupid does
one have to be to say "I think B isn't" when you say "A is, same
applies for B?"
....

Suit yourself. If you don't like it, it takes a few seconds to
plonk Cunningham, and possibly to threadplonk any threads he
starts. Then you won't be bothered. Some of us admire his
stick-to-it-ness. We don't really expect him to learn, but he has
at times. The problem is that he then forgets it all.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #28
Keith Thompson wrote:

From now on, if you post a chunk of nearly illegible code like what
you posted upthread, with no indentation and virtually no whitespace,
I will ask you to format it properly before I'll even consider helping
you fix any other problems.
It will feel good once you stop beating your head against the wall.

Brian
Jun 27 '08 #29
"Default User" <de***********@yahoo.comwrites:
Keith Thompson wrote:
>From now on, if you post a chunk of nearly illegible code like what
you posted upthread, with no indentation and virtually no whitespace,
I will ask you to format it properly before I'll even consider helping
you fix any other problems.

It will feel good once you stop beating your head against the wall.
Thanks for the advice.

Again.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #30
"Bill Cunningham" <no****@nspam.comwrites:
"Keith Thompson" <ks***@mib.orgwrote in message
news:87************@kvetch.smov.org...
>The syntax of a while statement is:

while ( expression ) statement

Note that that's a *single* statement. If you want the body to be
multiple statements, you need to wrap them in braces to create a
compound statement,

I see.

which is itself as single statement. (The same
>thing applies to if statements; you correctly used braces for those,

I think braces are required with if.
Did you ever try to read a C book? It seems you do not have much of an
idea of anything or what braces are for.
Jun 27 '08 #31
Keith Thompson wrote:
"Default User" <de***********@yahoo.comwrites:
It will feel good once you stop beating your head against the wall.

Thanks for the advice.
Happy to help!


Brian
Jun 27 '08 #32

"Eligiusz Narutowicz" <el*************@hotmail.comwrote in message
news:fv**********@registered.motzarella.org...
Did you ever try to read a C book? It seems you do not have much of an
idea of anything or what braces are for.
k and r 2 can sometimes go over my head. So I don't use it much but I do
have a little handy dandy little book called "C pocket reference". It's what
I do most of my reading from. It's a small reference and not a big tutorial
but it's pretty easy for me and on my level much more than some texts.

Bill
Jun 27 '08 #33
On Sun, 04 May 2008 21:25:27 GMT, "Bill Cunningham" <no****@nspam.com>
wrote:
>
"Eligiusz Narutowicz" <el*************@hotmail.comwrote in message
news:fv**********@registered.motzarella.org...
>Did you ever try to read a C book? It seems you do not have much of an
idea of anything or what braces are for.

k and r 2 can sometimes go over my head. So I don't use it much but I do
have a little handy dandy little book called "C pocket reference". It's what
I do most of my reading from. It's a small reference and not a big tutorial
but it's pretty easy for me and on my level much more than some texts.
Is this something you found on the web or did you buy it. Can you
provide a reference so we can check to see if it is the source of
misinformation you seem to be suffering from?
Remove del for email
Jun 27 '08 #34

"Barry Schwarz" <sc******@dqel.comwrote in message
news:hc********************************@4ax.com...
Is this something you found on the web or did you buy it. Can you
provide a reference so we can check to see if it is the source of
misinformation you seem to be suffering from?
It's a very small paper back book. Like a reference. From Oreilly books.

Bill
Jun 27 '08 #35
On 2 May, 22:40, "Bill Cunningham" <nos...@nspam.comwrote:
* * I have looked this program up and down and I don't see what's wrong with
it. But it always breaks and gives me an error "mode error" no matter which
mode binary or text I choose. This simple program is supposed to take as
argv[1] a "b" or "t" for binary or text. It's not taking anything.

#include <stdio.h>

int main(int argc, char **argv) {
*char *b;
*int a;
*FILE *ifp,*ofp;
*if (argc!=4) {
*fprintf(stderr,"usage error\n");
*return -1;
*}
*if (argv[1]=="b") {
*b="rb";
*}
*if (argv[1]=="t") {
*b="rt";
*}
*if (argv[1]!="t"||argv[1]!="b") {
*fprintf(stderr,"mode error\n");
*return -1;
*}
*if ((ifp=fopen(argv[2],b))==0) {
*fprintf(stderr,"open error i\n");
*return -1;
*}
*if ((ofp=fopen(argv[3],b))==0) {
*fprintf(stderr,"open error o\n");
*return -1;
*}
*while(a!=EOF)
*a=fgetc(ifp);
*fputc(a,ofp);
*printf("done\n");
*return 0;}

* * Is anyone good enough to glance at this and see what's wrong?
your space key is broken.
You can't be bothered to indent your code.
I can't be bothered to read your unindented code.

--
Nick Keighley
Jun 27 '08 #36

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
14143
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
22
3574
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
0
6075
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
11
2580
by: christopher diggins | last post by:
I am wondering if any can point me to any open-source library with program objects for C++ like there is in Java? I would like to be able to write things like MyProgram1 >> MyProgram2 >>...
1
3248
by: Eric Whittaker | last post by:
hi all, im trying to write my first c++ program. a success, but i can't get the window to stay open after user enters input. it just automatically closes. right now the end of my program looks...
9
4519
by: Hemal | last post by:
Hi All, I need to know the memory required by a c program. Is there any tool/utility which can give me the memory usage in terms of DATA segment, TEXT segment, BSS segment etc. I am working...
7
13247
by: ibtc209 | last post by:
I just started programming in C, and I need some help with this problem. Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s first card, and...
2
19320
Banfa
by: Banfa | last post by:
Posted by Banfa The previous tutorial discussed what programming is, what we are trying to achieve, the answer being a list of instructions constituting a valid program. Now we will discuss how...
0
13289
amitpatel66
by: amitpatel66 | last post by:
There is always a requirement that in Oracle Applications, the Concurrent Program need to be execute programatically based on certain conditions/validations: Concurrent programs can be executed...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7348
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.