Reading a file using fread

 /*:) fread_fileV1 :) have fun */  
 // header files  
 #include<unistd.h>  
 #include<stdio.h>  
 //main func  
 int main(int argc, char *argv[])  
 {  
  FILE *fp;  
  char buff[11];  
  int pid;  
  fp=fopen("baby","r");  
  pid=fork();  
  if(pid==0)  
  {  
  printf("Initial child pointer is %L\n",ftell(fp));  
  fread(buff,sizeof(buff),1,fp);  
  buff[10]='\0';  
  printf("child read is %s\n",buff);  
  printf("the child pointer after reading is %l\n",ftell(fp));  
  printf("the child is exiting \n");  
  }  
  else  
  {  
  wait(0);  
  printf("initial parent pointer is %l\n",ftell(fp));  
  fread(buff,sizeof(buff),1,fp);  
  buff[10]='\0';  
  printf("parent read is %s\n",buff);  
  printf("the parent poitner after read is %l\n",ftell(fp));  
  printf("parent exiting");  
  }  
  return 0;   
 }  

Comments

Popular posts from this blog

Setting up atalanta ATPG to work on Linux

Generating 16k ROM using Xilinx IP COREGEN and simulating it in modelsim

Sparse matrix - 3 tuple representation