using a char* for file
well i am trying to pass this parameter in a function --> char*[I]filename[/I]
[U][B]//i just wrote this as an example to explain clearer my question[/B][/U]
#include<stdio.h>
#include<stdlib.h>
void try (char *[I]filename[/I]) //[B] the question is how can i use the pointer to refer to a file? [/B]
{
printf("try");
}
int main ()
{
FILE *f=fopen("lol.txt","w+");
try(*[I]filename[/I]);
return 0;
}
terence193
Junior Poster in Training
57 posts since Apr 2008
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 0
qm anyways try is just for the example
I havent tried this
char buffer[20];
myFilename=(char*)buffer;
try(myFilename)
but by myFilename i wont be calling the FILE .. and if i change myFilename to *f then i get the incompatible type error.
terence193
Junior Poster in Training
57 posts since Apr 2008
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 0
zeroliken
Nearly a Posting Virtuoso
1,346 posts since Nov 2011
Reputation Points: 214
Solved Threads: 205
Skill Endorsements: 14
@zeroliken I have seen that thread before and it is very similar to my case but in my case, I need to pass (char * .. ) and that is what I cant seem to do correctly.
*edit
and char *.. is to resemble a file which is (or should be I think) opened globally.
terence193
Junior Poster in Training
57 posts since Apr 2008
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 0
this is what i attempted so far, but this code has many errors which I cant resolve:
#include<stdio.h>
#include<string.h>
typedef struct
{
FILE *f
f=fopen("gamestat.txt","w+");
char buffer[20];
*f=(char*)buffer;
} files;
void try2(files);
void try2 (p.char *f)
{
printf("try");
}
int main ()
{
files p;
try2(p.char*f);
return 0;
}
terence193
Junior Poster in Training
57 posts since Apr 2008
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 0