- #1
TheMathNoob
- 189
- 4
Homework Statement
How can you redefine a function in c. In this case I am trying to redefine fopen but it doesn't work because in the main the file doesn't change
Homework Equations
#include "InputLib.h"
FILE* file_open(char* pt)
{
FILE* fp = malloc(sizeof(FILE*)); // I tried this code without malloc and it doesn't work. I assume that this way would be better because I am allocating memory so fp won't be lost;
fp=fopen(pt,"w+");
return fp;[/B]
}
char* getName()
{
char* pt= calloc(SIZE,sizeof(char));
fgets(pt,SIZE,stdin);
return pt;
}
#ifndef INPUTLIB_H_
#define INPUTLIB_H_
#include "IntList.h"
char* getName();
FILE* file_open(char infile[]);
const int SIZE=50;
#endif /* INPUTLIB_H_ */
The Attempt at a Solution
#include "IntList.h"int main(void)
{
char C[80];
FILE* MyFile;
//printf("enter the name of the file");
printf("enter the name of the file");
fflush(stdout);
MyFile=file_open(getName());
printf("Enter a sentence");
fflush(stdout);
gets(C);
fprintf(MyFile,"%s",C);
fclose(MyFile);
}