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;
}

Recommended Answers

All 5 Replies

try is a keyword. Also, have you already allocated the memory space for character array pointed to by *filename? (By allocate, I mean like char buffer[20];myFilename=(char*)buffer;try(myFilename); or myFilename=new char[20];try(myFilename);

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.

@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.

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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.