• Twitter
  • Facebook
  • Google+
  • Instagram
  • Youtube

Monday, 15 August 2016

COMP202 - Week02 - Stage 2

This stage develops the following specific skills:
  • Reading binary data
  • Opening and closing files
  • Printing various data types using printf.
  • Using a simple command-line parameter.
Knowledge and Experience
  • reading a binary file with passed parameter 
    • int main(int argc, char *argv[])
    • after compile file, call the execution
    • ex: ./stage2 input-2.bin
      • argc must be 2, if not, print error by fprint(stderr, "message")
      • argv[0]: stage2
      • argv[1]: input-2.bin
  •  read the file and set it to the file pointer
    • FILE *fp = fopen(filename, "rb"); //r: read, b: binary
      • pass filename by argv[1]
    • check fp is null or not
      • if not, print out error by fprinpt
  • How to read binary data from start to end
    • function: fread - http://www.cplusplus.com/reference/cstdio/fread/
    • while( fread((void *)&initStruct.geese, sizeof(initStruct.geese), 1, fp) != 0 ) 
      • stop when eof
  • Print long integer - most important
    • use "%ld"

0 comments:

Post a Comment

Contact

Get in touch with me


Adress/Street

Jozi Studio -Sydney, New South Wales

Phone number

+(12) 3456 789

Website

www.learnwithjoe.blogpost.com.au