Xref: utzoo comp.unix.questions:13145 comp.unix.wizards:15831 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Re: system() --- the C function from hell? Keywords: system, unix, question, does anyone use this line? Message-ID: <10965@bloom-beacon.MIT.EDU> Date: 30 Apr 89 11:23:05 GMT References: <1827@uop.edu> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Followup-To: comp.unix.questions Organization: Massachusetts Institute of Technology Lines: 58 In article <1827@uop.edu> jeff@uop.edu (Jeff Ferguson) writes: > Hi kids, > > The system() call seems to wreak havoc with integer variables. >I have the following code: Since you have failed to provide all of the relevant code, most specifically the declaration of the variable str, I can't tell you for sure what is wrong, but I can tell you that it has nothing to do with system, and I can also tell you that what I suspect is wrong is that you are not allocated enough space for str so that your sprintf is overwriting your integer variables (You declared str to be "char *," perhaps?). Here's your sample code in a simple program wrapper and a sample run of it that works: ************************* #include main() { int hip, lowp; char str[50]; fprintf(stdout, "Enter hip: "); fflush(stdout); scanf("%d", &hip); fprintf(stdout, "Enter lowp: "); fflush(stdout); scanf("%d", &lowp); sprintf(str, "/bin/mkdir directory"); system(str); fprintf(stdout, "lowp = %d, hip = %d\n", lowp, hip); } ************************* oliver% a.out Enter hip: 3 Enter lowp: 3 lowp = 3, hip = 3 oliver% ls -d directory directory/ oliver% ************************* Jonathan Kamens USnail: MIT Project Athena 410 Memorial Drive, No. 223F jik@Athena.MIT.EDU Cambridge, MA 02139-4318 Office: 617-253-4261 Home: 617-225-8218 P.S. I have directed follow-ups to comp.unix.questions, as you should have done. Did this really need to go to comp.unix.wizards in the first place?