Xref: utzoo comp.unix.questions:13146 comp.unix.wizards:15832 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!leah!rpi!weber.cs.rpi.edu!mcintyrd From: mcintyrd@cs.rpi.edu (David McIntyre) 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: <2349@rpi.edu> Date: 30 Apr 89 11:45:44 GMT References: <1827@uop.edu> Sender: usenet@rpi.edu Organization: Rensselaer Polytechnic Institute, Troy, NY Lines: 32 In article <1827@uop.edu> jeff@uop.edu (Jeff Ferguson) writes: > The system() call seems to wreak havoc with integer variables. >I have the following code: > >int lowp, hip; >... >scanf("%d", &hip); >scanf("%d", &lowp); >sprintf(str, "/bin/mkdir directory"); >system(str); >... > >I printed the values of LOWP and HIP before the system() call, and >everthing was pee-chee (like the folder). I print them out after >the call and the values have been blown to high Heaven: before they >were both 3, while after system(str) they are in the tens of millions. I would suggest that str is a (char *) variable that has not had any space allocated for it, and it is overwriting the two integers somehow. You should either make str something like char str[20]; or malloc it, something like this: str = (char *)malloc(20*sizeof(char)); Dave "mr question" McIntyre | "....say you're thinking about a plate mcintyre@turing.cs.rpi.edu | of shrimp.....and someone says to office : 518-276-8633 | you `plate,' or `shrimp'......" home : 518-271-6664 |