25 Aug, 2009, Bojack wrote in the 1st comment:
Votes: 0
Is there a way to make a temp pointer? Or something related to a pointer? OR even a simple way of doing this:
Im trying to open a specific file by a person's name in the rom god directory. The god directory holds a person's immortal name and in that file is their imm level and title. What im trying to do is create some way of opening this file to do a check on a person's password to what a person typed. This code below hopefully will give people an example:
sprintf (buf, "%s%s", GOD_DIR, capitalize(ch->name) );
if (!(fp = fopen (buf, "r")) )
{
logstr (LOG_BUG, "Cant open %s in GOD_DIR", ch->name);
sendch ("The system can't find your immortal name.\n\r", ch);
exit(0);
return;
}

fseek (fp, 0, SEEK_END);
lsize = ftell (fp);

buffer = (char *) malloc (sizeof(char) * lsize);
if (!buffer)
{
sendch ("Error setting memory.\n\r", ch);
exit(1);
return;
}

result = fread (buffer, 1, lsize, fp);
if (result != lsize)
{
sendch ("Error reading file.\n\r", ch);
exit(2);
return;
}

if (!str_cmp(ch->pcdata->pwd, arg))
{
char flag[MAX_STRING_LENGTH] = result;
char str1[5], str2[4], str3[20];
int lvl, trust;

sscanf (result, "%s %s %2d %s %2d", str1, str2, lvl, str3, &trust);
if (!str_cmp(str1, "bb") || IS_SET(ch->act, PLR_FIRED) )
{
sendch ("Nice try.\n\r", ch);
return;
}
25 Aug, 2009, David Haley wrote in the 2nd comment:
Votes: 0
It's definitely possible to allocate a string on the fly and release it. With the disclaimer that I haven't studied the above code in great detail line by line, what exactly is it doing or not doing that it shouldn't or should be doing?
25 Aug, 2009, Bojack wrote in the 3rd comment:
Votes: 0
Well fseek is reading till it finds the end of the file then ftell gets the size of the file and sets lsize to it. After result becomes the pointer but the problem is im not sure if the pointer is broken down. I was trying to find an easier way to break it down without using fread and case 'E' etc etc. After I do that problem, I want to use string scan to check and see if they match. Does that help david?
25 Aug, 2009, Tyche wrote in the 4th comment:
Votes: 0
Don't know what you are asking, but in reading the code fragment, I think that…
fseek (fp, 0, SEEK_END);
lsize = ftell (fp);

Should be followed by…
rewind(fp);

In any case, rather than the approach you are using,
I would read the file line by line until I found the field I was seeking,
assuming these are text files.
0.0/4