Mail Archives: djgpp/1999/09/01/00:07:00
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 -