Xref: utzoo comp.sys.amiga:34655 comp.lang.c:19050 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!sun-barr!apple!motcsd!xdos!doug From: doug@xdos.UUCP (Doug Merritt) Newsgroups: comp.sys.amiga,comp.lang.c Subject: Re: C problems Keywords: Amiga, Manx 3.6a Message-ID: <365@xdos.UUCP> Date: 31 May 89 02:16:09 GMT References: Reply-To: doug@xdos.UUCP (Doug Merritt) Followup-To: comp.sys.amiga Organization: Hunter Systems, Mountain View CA (Silicon Valley) Lines: 62 In article armhold@topaz.rutgers.edu (George Armhold) writes: > >Also, here's some source I tried today. What I'm trying to do is >simply copy one file to another. When I compile it, I get error 125 >which means "too many subscripts or indirection on integer". It occurs >wherever I mention argv[x]. Oh well, I may as well join the hundreds of others who will all point out the same problems. I usually resist but I feel like burning bandwidth for once: >main(argc, argv) >{ You need to declare the parameters here, like for instance: main(argc, argv) int argc; char **argv; > while ((c=getc(fp1)!=EOF)) > putc(fp2); There are two problems here...one is that the while() is misparenthesized, it should be: > while ((c=getc(fp1)) != EOF) As written it was doing (c = (getc(fp1) != EOF)), which always assigns either a zero or a one to 'c'. Second, you're not giving the right parameters, 'c' is missing from the call: putc(c, fp2); These are all pretty obvious bugs, so I suspect that your original frustration in not being sure which functions to use in the first place became a problem in itself. Pirsig called this a "gumption trap" in "Zen and the Art of Motorcycle Maintenence". The recommended cure is to stop, cool off, relax, and then go back to what you were doing. For various reasons (style, portability, forming bug-avoiding habits) you should also close the files before exiting, and also call exit explicitly: fclose(fp1); fclose(fp2); exit(0); The explicit exit provides a clean return code so that your programs could be used in your 'make' scripts. For the same reason, your error exits should give a non-zero exit code: if (...open fails...) exit(1); Or on the Amiga, perhaps: exit(10); Programming in C is fun once you get used to it. Doug -- Doug Merritt {pyramid,apple}!xdos!doug Member, Crusaders for a Better Tomorrow Professional Wildeyed Visionary "Welcome to Mars; now go home!" (Seen on a bumper sticker off Phobos)