"user923005" <dcorbit@[EMAIL PROTECTED]
> wrote in message
news:6f66a742-0b5b-4e16-b314-dc5e818b6cf0@[EMAIL PROTECTED]
> #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 ****table, 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


|