spencer@ogg.cgrg.ohio-state.edu (Steve) (12/03/87)
Let's get machines out of the way first: this program runs on a Vax, 4.3BSD. I am writing an program which utilizes curses (so that I link with the curses and termcap libraries). My problem is this: when I try to open a file to write to it (create the file anew), I get a core dump. When I make the function which opens the file and writes to it a stand-alone program, it works fine. The function, in the form of the stand-alone program, is shown below: =========================================== #include <stdio.h> main() { FILE *mf; mf = fopen("mapp","w"); if (mf==NULL) { printf("could not open mapp\n"); } else { printf("opened mapp\n"); fprintf(mf,"Hello world 1234567890\n"); fclose(mf); } } ========================================== <stdio.h> is included in the program I am writing, and the only other change I made to make this program a function is change the name from main() to printmap(). My question is this: given what sketchy details I have given, can anyone figure out WHY this won't work? Running "dbx" on this program reveals that it stopped in the fopen() statement, running a function called Legalfilename(), which in turn was running a function called writev(). (from the "where" command in dbx) Maybe I'm wrong in assuming that curses has something to do with it, but frankly, I'm stumped. My sincere thanks to anyone who can lead me out of this mess. -- "Travis McGee's still in Cedar Key, That's what old John MacDonald said...." - Jimmy Buffett Stephen Spencer, Graduate Student | The Computer Graphics Research Group | {cbosgd,ucbvax}!osu-cis!ogg!spencer The Ohio State University | spencer@ogg.cgrg.ohio-state.edu 1501 Neil Avenue, Columbus OH 43210 |
poetry@utgpu.UUCP (12/08/87)
In article <1014@ogg.cgrg.ohio-state.edu> spencer@ogg.cgrg.ohio-state.edu (Steve) writes: >I am writing an program which utilizes curses (so that I link with >the curses and termcap libraries). My problem is this: when I try to >open a file to write to it (create the file anew), I get a core dump. >When I make the function which opens the file and writes to it a >stand-alone program, it works fine. The function, in the form of the >stand-alone program, is shown below: >=========================================== >#include <stdio.h> > >main() >{ >FILE *mf; > /* body of the function using printf, etc. */ >} >========================================== What alerted my attention is the <stdio.h>. I did some curses programming in the summer (haven't touched it since) in a different environment and I vaguely remember having had a similar problem. ><stdio.h> is included in the program I am writing, and the only other >change I made to make this program a function is change the name from >main() to printmap(). Precisely. "You can't mix windows with regular output functions such as printf() because refresh() doesn't know what those output functions did or even that they were called." (quote from John Strang: Programming with Curses) I think this is where the problem is. In addition to the source above, S.G. Kochan + P.H. Wood: Topics in 'C' Programming has an excellent discussion of curses (and much more; one of the few truly great books on 'C'). i.e.