Thread: Seeking help understanding some C code!

  1. #1
    Registered User
    Join Date
    Jan 2018
    Posts
    1

    Seeking help understanding some C code!

    int main( int argc, char *argv[]){

    int j = 64;
    int fileDescriptor;
    char buffer[64];
    FILE *fp;

    fd = open("tmpout_fd", O_CREAT|O_WRONLY|O_TRUNC);
    write(fileDescriptor,&j,sizeof(int));
    sprintf(buffer,"j=%d\n",j);
    write(fileDescriptor,buffer,strlen(buffer));
    close(fileDescriptor);



    also



    filePointer = fopen("tmpout_fp","w");
    fwrite(&j,1,sizeof(int),filePointer);
    fprintf(filePointer,"j=%d\n",j);
    fclose(filePointer);



    thank you ppls

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    What don't you understand?

    Both do basically the same thing.
    The first uses the POSIX API.
    The second uses the LibC API.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. understanding this code
    By bellagomes21 in forum C Programming
    Replies: 2
    Last Post: 02-29-2016, 08:09 PM
  2. Need help understanding this code
    By sameertelkar in forum C Programming
    Replies: 11
    Last Post: 01-04-2013, 07:36 AM
  3. Seeking Help for Code Explanation
    By Beginner1987 in forum C Programming
    Replies: 2
    Last Post: 12-05-2011, 09:49 AM
  4. code understanding
    By elwad in forum C Programming
    Replies: 5
    Last Post: 04-18-2009, 06:57 AM
  5. Help understanding a code
    By lolguy in forum Networking/Device Communication
    Replies: 2
    Last Post: 03-15-2009, 04:13 PM

Tags for this Thread