Message-Id: <199909010454.HAA01339@ankara.Foo.COM> From: "S. M. Halloran" Organization: User RFC 822- and 1123-compliant To: djgpp AT delorie DOT com Date: Wed, 1 Sep 1999 08:59:29 +0200 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: Code help pls In-reply-to: <37cc35bf.1702101@news.erols.com> X-mailer: Pegasus Mail for Win32 (v3.12) Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk These are C language beginner's mistakes you are making here, by failing to initialize pointers to memory areas with the memory areas you need to set aside. The variables 'ename' and 'epass' should be either pointers to dynamic (malloc'd) memory or to arrays of type char (better in your case). Moreover, you should call functions that mediate input (keyboard, etc.) to these memory areas and which allow you to control the bounds of memory so that you don't exceed them: there are some people who don't like the use of gets() for example and prefer fgets(). Since you are posting through an NNTP gateway, you have access to comp.lang.c, surely, and would probably benefit from additional explanations of the fundamentals of C language by the regulars of that newsgroup. On 31 Aug 99, Billy was found to have commented thusly: > #include > #include > #include > #include > > int main() > { > FILE *infile, *outfile; > char *ename, *cpass, *epass; > > clrscr(); > printf("Enter character's name:\n"); > gets(ename); > > infile = fopen(strcat("players/", ename), "r"); > if (!infile) > { > printf("New player!\n"); > printf("Enter password:\n"); > gets(epass); > outfile = fopen(strcat("players/", ename), "w"); > fputs(epass, outfile); > fclose(outfile); > printf("Welcome!\n"); > } > ..... > > I wanted the code to create a file with the same > filename as the player's name (in the players subdir), > and in it I wanted the player's password. > This is the output I get (the player "foobar" doesn't > exist): > > Enter character's name: > foobar > oobarEnter password: > blah > Welcome! > > > A file is created in the players/ dir > called "foobarfoobar" with the correct password > in it, and you see the "oobar" has replaced > the "New player!" line that I wanted in. What > did I do wrong? > Thanks alot. > Mitch Halloran Research (Bio)chemist Duzen Laboratories Group Ankara TURKEY