Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > program bug
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 36 Topic 26044 of 26198
Post > Topic >>

program bug

by "Bill Cunningham" <nospam@[EMAIL PROTECTED] > May 2, 2008 at 09:40 PM

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




 36 Posts in Topic:
program bug
"Bill Cunningham&quo  2008-05-02 21:40:19 
Re: program bug
"Bill Cunningham&quo  2008-05-02 21:53:34 
Re: program bug
Robert Gamble <rgamble  2008-05-02 15:08:03 
Re: program bug
Robert Gamble <rgamble  2008-05-02 15:05:58 
Re: program bug
"Bill Cunningham&quo  2008-05-02 22:16:27 
Re: program bug
CBFalconer <cbfalconer  2008-05-02 18:47:28 
Re: program bug
"Bill Cunningham&quo  2008-05-02 22:21:04 
Re: program bug
Robert Gamble <rgamble  2008-05-02 15:28:04 
Re: program bug
"Bill Cunningham&quo  2008-05-03 20:42:30 
Re: program bug
Keith Thompson <kst-u@  2008-05-03 14:48:48 
Re: program bug
"Bill Cunningham&quo  2008-05-03 22:58:24 
Re: program bug
Keith Thompson <kst-u@  2008-05-03 18:08:44 
Re: program bug
"Default User"   2008-05-04 03:20:33 
Re: program bug
Keith Thompson <kst-u@  2008-05-03 21:17:13 
Re: program bug
"Default User"   2008-05-04 19:03:07 
Re: program bug
vippstar@[EMAIL PROTECTED  2008-05-03 16:21:48 
Re: program bug
CBFalconer <cbfalconer  2008-05-03 20:29:01 
Re: program bug
Joe Wright <joewwright  2008-05-02 18:25:33 
Re: program bug
Ian Collins <ian-news@  2008-05-03 10:28:17 
Re: program bug
"Bill Cunningham&quo  2008-05-02 22:36:04 
Re: program bug
Robert Gamble <rgamble  2008-05-02 15:36:31 
Re: program bug
Ian Collins <ian-news@  2008-05-03 11:31:53 
Re: program bug
Joe Wright <joewwright  2008-05-02 20:18:17 
Re: program bug
Ian Collins <ian-news@  2008-05-03 12:31:09 
Re: program bug
"Bill Cunningham&quo  2008-05-02 23:15:17 
Re: program bug
Keith Thompson <kst-u@  2008-05-02 23:56:46 
Re: program bug
Richard Heathfield <rj  2008-05-03 07:04:24 
Re: program bug
CBFalconer <cbfalconer  2008-05-02 18:50:15 
Re: program bug
user923005 <dcorbit@[E  2008-05-02 21:25:53 
Re: program bug
"Bill Cunningham&quo  2008-05-03 15:52:27 
Re: program bug
vippstar@[EMAIL PROTECTED  2008-05-03 09:01:52 
Re: program bug
Eligiusz Narutowicz<el  2008-05-04 08:41:56 
Re: program bug
"Bill Cunningham&quo  2008-05-04 21:25:27 
Re: program bug
Barry Schwarz <schwarz  2008-05-04 15:20:34 
Re: program bug
"Bill Cunningham&quo  2008-05-06 02:30:36 
Re: program bug
Nick Keighley <nick_ke  2008-05-06 02:28:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue May 13 14:48:27 CDT 2008.