K
kak3012
Hi;
Here is the main code and the function. I think it does not return the (char
pIn)
I might be mistaken a lot of place like returning a value, choosing right
function type and so on. That is why I could not figure it by myself.
Can anyone help me I am new to C++ functions.
MAIN.CPP
------------------------
FILE Open_File(char *FILEStatic,char *OpenStyle,char *INFO);
int main(int argc, char *argv[])
{
// I get the file name from the command line
// And open it with my function
// I will use the pIn value to read the data with fread. But it returns NULL
pIn=Open_File(FILEin,"rb","INPUT");
}
MYFUCNTION
------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char Buffer[1024];
extern "C"
{
FILE Open_File(char *FILEStatic,char *OpenStyle,char *INFO);
}
FILE Open_File(char *FILEStatic,char *OpenStyle,char *INFO)
{
FILE *pStatic;
pStatic = fopen(FILEStatic, OpenStyle);
if (pStatic == NULL)
{
sprintf(Buffer, " ERROR: %s=%s\n", INFO,FILEStatic);
printf(Buffer);
// return (2);
}
else
{
sprintf(Buffer, " OK: %s=%s\n", INFO,FILEStatic);
printf(Buffer);
}
return *pStatic;
}
Here is the main code and the function. I think it does not return the (char
pIn)
I might be mistaken a lot of place like returning a value, choosing right
function type and so on. That is why I could not figure it by myself.
Can anyone help me I am new to C++ functions.
MAIN.CPP
------------------------
FILE Open_File(char *FILEStatic,char *OpenStyle,char *INFO);
int main(int argc, char *argv[])
{
// I get the file name from the command line
// And open it with my function
// I will use the pIn value to read the data with fread. But it returns NULL
pIn=Open_File(FILEin,"rb","INPUT");
}
MYFUCNTION
------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char Buffer[1024];
extern "C"
{
FILE Open_File(char *FILEStatic,char *OpenStyle,char *INFO);
}
FILE Open_File(char *FILEStatic,char *OpenStyle,char *INFO)
{
FILE *pStatic;
pStatic = fopen(FILEStatic, OpenStyle);
if (pStatic == NULL)
{
sprintf(Buffer, " ERROR: %s=%s\n", INFO,FILEStatic);
printf(Buffer);
// return (2);
}
else
{
sprintf(Buffer, " OK: %s=%s\n", INFO,FILEStatic);
printf(Buffer);
}
return *pStatic;
}