Articles Comments

{ Berbagi, Menulis, Dan Mengajar } Ilmu… » 7. Operating System » ANSI C on Linux – readfile… Dasar Disik ae mbah

ANSI C on Linux – readfile… Dasar Disik ae mbah

#include 
#include 
#include 

#define DISPLAY 80
#define PAGE_LENGTH 20

int main(int argc, char *argv[])
{
   char filename[80]=“c:\\myfile.txt”;
   FILE *pfile;
   unsigned char buffer[DISPLAY/4 - 1];
   int count = 0;
   int lines = 0;
   int i = 0;

   if((pfile = fopen(filename, “rb”)) == NULL){
       printf(“Sorry, can’t open %s”, filename);
       return -1;
   }

   while(!feof(pfile))
   {
     if(count < sizeof buffer) /* If the buffer is not full  */
       printf(“%c \n”, (unsigned char)fgetc(pfile));

     if(count < sizeof buffer) /* If the buffer is not full  */
       printf(“%02X \n”, (unsigned char)fgetc(pfile));

   }

   fclose(pfile);
   return 0;
}



Filed under: 7. Operating System

Leave a Reply

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>