Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
I wrote this routine which is supposed to open a fi
I wrote this routine which is supposed to open a file:
myfopen(char *filename, FILE *fp)
{
fp = fopen(filename, "r");
}
But when I call it like this:
FILE *infp;
myfopen("filename.dat", infp);
the infp variable in the caller doesn't get set properly.
✍: Guest
Functions in C always receive copies of their arguments, so a function can never ``return'' a value to the caller by assigning to an argument.
For this example, one fix is to change myfopen to return a FILE *:
FILE *myfopen(char *filename)
{
FILE *fp = fopen(filename, "r");
return fp;
}
and call it like this:
FILE *infp;
infp = myfopen("filename.dat");
Alternatively, have myfopen accept a pointer to a FILE * (a pointer-to-pointer-to-FILE):
myfopen(char *filename, FILE **fpp)
{
FILE *fp = fopen(filename, "r");
*fpp = fp;
}
and call it like this:
FILE *infp;
myfopen("filename.dat", &infp);
2015-10-09, 1309👍, 0💬
Popular Posts:
If cookies are not enabled at browser end does form Authentication work? No, it does not work.
How To Process Query Result in PL/SQL? - Oracle DBA FAQ - Introduction to PL/SQL You can run queries...
1. The basics first, please define the web in simple language? How is it connected with internet? Wh...
Where Do You Download JUnit? Where do I download JUnit? I don't think anyone will ask this question ...
How do we access attributes using “XmlReader”? Below snippets shows the way to access attributes. Fi...