Path: utzoo!attcan!uunet!vsedev!hudson From: hudson@vsedev.VSE.COM (C Hudson Hendren III) Newsgroups: comp.unix.wizards Subject: Re: Unix problem or C problem? Message-ID: <1293@vsedev.VSE.COM> Date: 19 Jan 89 17:08:12 GMT References: <245@ibd.BRL.MIL> Reply-To: hudson@vsedev.VSE.COM (C Hudson Hendren III) Organization: VSE Software Development Lab Lines: 41 In article <245@ibd.BRL.MIL> heilpern@brl.arpa (Mark A. Heilpern (IBD) ) writes: > > while (fscanf(input,"%d",stars)!=EOF) { ^^^^^ You need to use an ampersand before the variable name so that fscanf has the address of "stars". The line should read: while (fscanf(input,"%d",&stars)!=EOF) { > fprintf(stderr,"OK to this point.\n"); > fprintf(output,"%4d |",lines++); > stars /= 50; > for (count = 0; count <= stars; count++) > fprintf(output,"*"); > fprintf(output,"\n"); > } > > I get the following error message, NOT put out from my program: > >PROTECTION VIOLATION: name='plot', pid=15943, pc=a410cdc, ps=80000180 >Illegal instruction > > The 'plot' program is not setu/gid, I've never seen a PROTECTION > VIOLATION error like this before. Any insights would be greatly > appreciated. It would appear that PROTECTION VIOLATION on you version of unix is what most of us know to be a "segmentation violation". This error occurs when your program attempts to alter a memory location outside of it's allowed area. When you simply passed "stars" to fscanf() you were passing the actual value of stars and not the address location of "stars". The fscanf() function expects an address. If the value of "stars" happened to be zero, then fscanf() would assume that you wanted the decimal number scanned in to be stored at location zero. This is either damaged another variable or it clobbered an instruction (depending upon how your linker arranges the final binary). I guess that you clobbered an instruction since you got an illegal instruction fault. -- ==> ..!uunet!vsedev!hudson [hudson@vsedev.vse.com] (C Hudson Hendren III) <== ==> These are my opinions and are not necessarily those of VSE Corporation. <== ==> MS-DOS was created to keep idiots away from UNIX computers <==