#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LEN 100
int main(int argc,char** argv)
{
FILE* fp =fopen("./test.txt","r+");
char *ptr=NULL;
if(fp==NULL){
perror("fopen");
return -1;
}
int fw =fwrite("hello world",sizeof(char),strlen("hello world"),fp);
if(fw==0){
printf("write failed\n");
return -1;
}
char* buf=(char*)malloc(sizeof(char)*LEN);
if(buf==NULL){
perror("malloc");
return -1;
}
ptr=buf;
fseek(fp,0,SEEK_SET);
#include <string.h>
#include <stdlib.h>
#define LEN 100
int main(int argc,char** argv)
{
FILE* fp =fopen("./test.txt","r+");
char *ptr=NULL;
if(fp==NULL){
perror("fopen");
return -1;
}
int fw =fwrite("hello world",sizeof(char),strlen("hello world"),fp);
if(fw==0){
printf("write failed\n");
return -1;
}
char* buf=(char*)malloc(sizeof(char)*LEN);
if(buf==NULL){
perror("malloc");
return -1;
}
ptr=buf;
fseek(fp,0,SEEK_SET);
//int fr =fread(buf,sizeof(char),LEN,fp);
while(1){
if(fread(ptr++,1,1,fp)==0)
break;
}
printf("buf:%s\n",buf);
free(buf);
return 0;
}