--- In [email protected], Paul David <[EMAIL PROTECTED]> wrote:
>
> 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]
>
Dude....
U have already written the error in your program as the subject....
the parameters of the writefile() function are of type CHAR * not
INT...
so change them... because u r passing strings not integers to write
file....