delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/31/23:04:44

From: mordanbr AT hotmail DOT com (Billy)
Newsgroups: comp.os.msdos.djgpp
Subject: Code help pls
Date: Tue, 31 Aug 1999 20:12:55 GMT
Lines: 49
Message-ID: <37cc35bf.1702101@news.erols.com>
Mime-Version: 1.0
X-Trace: 7fc9fK4wZn/tCJP3yHCdjcNHYIy8wtYQo6Midq0OvvQ=
X-Complaints-To: abuse AT rcn DOT com
NNTP-Posting-Date: 31 Aug 1999 20:12:52 GMT
X-Newsreader: Forte Agent 1.5/32.451
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

#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?
Thanks alot.


- Raw text -


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