Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!jwt!john From: john@jwt.UUCP (John Temples) Newsgroups: comp.os.msdos.programmer Subject: Re: using "system" in C Message-ID: <1991Apr5.024832.2361@jwt.UUCP> Date: 5 Apr 91 02:48:32 GMT References: Distribution: comp Organization: Private System -- Orlando, FL Lines: 30 In article jono@dec06.cs.monash.edu.au (Jonathan Oliver) writes: > system("copy file1 file2"); > >there was not enough memory to perform the copy. The two problems with your approach are that system() has to load a copy of the command processor to do its job (which takes additional time and memory), and you're assuming that there's a command called "copy" on the system running your program. Since "copy" is a COMMAND.COM internal command, and not everyone who runs DOS uses COMMAND.COM, your program is non-portable. Also, system() usually fails when your switch character is not set to "/". In other words, system() is not usually a wise choice in any "serious" program. You should open "file1" and "file2" and do the copy yourself, something like this: int copy(FILE *infile, FILE *outfile) { char buf[BUFSIZ]; int cnt; while (cnt = fread(buf, sizeof(*buf), sizeof(buf), infile)) if (fwrite(buf, sizeof(*buf), cnt, outfile) != cnt) return 1; /* probably disk full */ return 0; } -- John W. Temples -- john@jwt.UUCP (uunet!jwt!john)