edit: took out the code since I posted updated code a few posts down
edit: took out the code since I posted updated code a few posts down
> FileOpen(&fileinp, dataFile, &length);
You need an extra * in several places then.
Code:void FileOpen(FILE **fileptr, char *file_name, int *lengthptr)
{
printf("Please enter the filename you wish to open : ");
scanf("%s", file_name);
*fileptr = fopen(file_name, "r");
if (*fileptr == NULL)
{
printf("An error has occurred while attempting to open the file\n");
exit(-1);
}
while(fgetc(*fileptr) != EOF)
{
length++;
}
}
ooooh, so that extra * in the prototype is what was needed, Ok. Thanks alot!
Ok, so the extra * allowed the file input to work out well, but I'm still having issues with the length pointer counter actually incrementing.
I pass the variable by reference "length" to the function, and the value of length is always zero. However, when I copy/paste that exact same code into main and swap out the pointers for the regular variables it works perfectly fine. Am I not allowed to do an increment to lengthptr? Am I missing something that would keep lengthptr from incrementing?Code:void FileOpen(FILE *fileptr, char *file_name, int *lengthptr)
{
printf("Please enter the filename you wish to open : ");
scanf("%s", file_name);
fileptr = fopen(file_name, "r");
if (fileptr == NULL)
{
printf("An error has occurred while attempting to open the file\n");
exit(-1);
}
while(fgetc(inp1) != EOF)
{
length++;
}
}
(this is what I would put into main, which would work out fine)Code:while ( fgetc(fileinput) != EOF
{
length++;
}
Same thing - use a *
Though watch out for
++*p
is different from
*p++