#include <stdio.h>
void main(void)
{
FILE *fp;
char list[]="hello world\0";
int numread=0;
int numwrite=0;
/*open file*/
if((fp=fopen("test.txt","w+t"))!=NULL)
{
numwrite=fwrite(list,sizeof(char),11,fp);//list[i]->fp
printf("Write %d items\n",numwrite);
fclose(fp);
}
else
printf("Problem opening the file\n");
if((fp=fopen("test.txt","r+t"))!=NULL)
{
/*Attempt to read in 25 characters*/
numread=fread(list,sizeof(char),11,fp);
printf("Number of items read=%d\n",numread);
printf("Contents of buffer=%.25s\n",list);
fclose(fp);
}
else
printf("File could not be opened\n");
}