Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!unido!rwthinf!cip-s01!wolfram From: wolfram@cip-s01.informatik.rwth-aachen.de (Wolfram Roesler) Newsgroups: comp.lang.c Subject: Re: Memor fault, Core dump Keywords: memory fault, coredump Message-ID: Date: 5 Jun 91 11:21:38 GMT References: <1991May21.160406.20825@ux1.cso.uiuc.edu> Sender: news@rwthinf.UUCP Lines: 33 nnj20229@uxa.cso.uiuc.edu (Nesha Nicole Jones) writes: >I am having a small problem debugging a program of mine. I get a memory >fault after a fprintf statement. First idea: did you pass the FILE* as the first arg to fprintf? This is usually the reason for me... >I was trying to allow the user to input >more than one line of information at a prompt. Ha! Just imagine the user inputs a line like: "hello you %s", then you will have `fprintf(fp,"hello you %s");'. fprintf will then encounter the %s, take something from its vararg list, assume it's a pointer and BOUMMMMM! To print something the user has entered (say, in a string named St), NEVER say `fprintf(fp,St)' but use `fprintf(fp,"%s",St)' or even better `fputs(St,fp)'. You should use [sf]printf only if you actually want to make use of the format elements introduced by '%'. The same problem is `sprintf(s1,s2)', use strcpy instead. >also, I read in two values, a date and a time. I strcat the date and time >together and the value for date is somehow changed to the 5th char in time >ex. 09:45 date= 5 Please explain that more precisely. >Any suggtestions about why this happens would also be helpfull. I hope so. BCingU \/\/olfram