From: Nate Eldredge Newsgroups: comp.os.msdos.djgpp Subject: Re: Code help pls Date: Tue, 31 Aug 1999 14:30:01 -0700 Organization: Harvey Mudd College Lines: 53 Message-ID: <37CC4959.AD1564DB@hmc.edu> References: <37cc35bf DOT 1702101 AT news DOT erols DOT com> NNTP-Posting-Host: mercury.st.hmc.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: nntp1.interworld.net 936134998 81936 134.173.45.219 (31 Aug 1999 21:29:58 GMT) X-Complaints-To: usenet AT nntp1 DOT interworld DOT net NNTP-Posting-Date: 31 Aug 1999 21:29:58 GMT X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.12pre4 i586) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Billy wrote: > > #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? None of your pointers point to anything, and you can't strcat to a literal. You probably want to use arrays for your strings. -- Nate Eldredge neldredge AT hmc DOT edu