I am trying to use parameters to the function writefile() to determine
the filename of the file, the mode it opens the file in, and the data
it writes to the file, but when i go to compile the source code i get
the following errors:
/Users/paul/Desktop/ftestf.c: In function writefile:
/Users/paul/Desktop/ftestf.c:22: warning: passing argument 1 of
fopen makes pointer from integer without a cast
/Users/paul/Desktop/ftestf.c:22: warning: passing argument 2 of
fopen makes pointer from integer without a cast
/Users/paul/Desktop/ftestf.c:33: warning: passing argument 2 of
fprintf makes pointer from integer without a cast
I'm a begginer to C and i don't know how to fix this problem
I also intend to make the same changes to readfile()
the source code is:
#include <stdio.h>
main()
{
writefile( "a+", "test.txt", "\nTesting...\n");
readfile();
return 0;
}
int writefile(int mode, int filename, int data1 )
{
FILE *ofp; /* declare a FILE pointer */
ofp = fopen(filename, mode);
/* create a text file for writing/appending */
if(ofp == NULL)
{
printf("\nError: can't create file.\n\07");
/* fclose(file); DON'T PASS A NULL POINTER TO fclose !! */
return 1;
}
else
{
fprintf(ofp, data1);
printf("Now closing File...\n");
fclose(ofp);
}
}
readfile()
{
char c; /* declare a char variable */
FILE *ifp; /* declare a FILE pointer */
ifp = fopen("test.txt", "r");
/* open a text file for reading */
if(ifp == NULL)
{
fprintf(stderr,"\nError: can't open file.\n\07");
/* fclose(file); DON'T PASS A NULL POINTER TO fclose !! */
return 1;
}
else
{
printf("File opened successfully. \n\t\tContents:\n\n");
while(1)
{ /* keep looping... */
c = fgetc(ifp);
if(c != EOF)
{
printf("%c", c);
/* print the file one character at a time */
}
else
{
break; /* ...break when EOF is reached */
}
}
printf("\n\nNow closing file...\n");
fclose(ifp);
}
}
[Non-text portions of this message have been removed]
------------------------------------
To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.Yahoo!
Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/c-prog/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/c-prog/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/