delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/09/01/00:07:00

From: Nate Eldredge <neldredge AT hmc DOT edu>
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
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 <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> #include <conio.h>
> 
> 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019