On Wed 2008-07-09 19:31:24 UTC-0700, Paul David ([EMAIL PROTECTED]) wrote:
> #include <stdio.h>
>
> main()
> {
> writefile( "a+", "test.txt", "\nTesting...\n");
> readfile();
> return 0;
> }
Usually you put main() at the end of your source file. Then the
compiler will know the correct parameters for writefile() and
readfile().
You are passing a string "a+" to writefile() but it is expecting an
int. Likewise the two other parameters.
> int writefile(int mode, int filename, int data1 )
Change this to:
int writefile(const char *mode, const char *filename, const char *data)
> fprintf(ofp, data1);
You should probably use fputs() or fwrite() here.
> 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 */
> }
> }
A simpler way to write this is:
c = fgetc(ifp);
while (c != EOF)
{
putchar(c);
c = fgetc(ifp);
}
Regards
Andrew