Thread: file size

  1. #16
    Registered User
    Join Date
    Jul 2007
    Location
    Hyderabad
    Posts
    35
    hi friends,

    thanx for different views on this.

    i tried with ftell

    size1=ftell(fp);
    fprintf(fp,"%s %0.4f %0.4f\n",sampling,pos,rat);
    size2=ftell(fp);

    printf("%d",size2-size1);


    then the optput is
    176
    203
    230
    257
    284
    311
    355
    ..
    ..

    but the way writing in to file like

    2007-10-10;2:10:25 45 100
    2007-10-10;2:10:26 145 100
    2007-10-10;2:10:27 245 100

    like wise writing into file.

    my doubt is will fprintf return characters including space ?
    ftell returning bytes or postion in the file?

    can we calculate with printf no: of bytes written to file?
    will the above code returning bytes?

  2. #17
    Registered User
    Join Date
    Jul 2007
    Location
    Hyderabad
    Posts
    35
    hi friends

    thanx for reply

    size1=ftell(fp);
    fprintf(fp,"%s %0.4f %0.4f",sampling,pos,rat);
    size2[=ftell(fp);

    printf("%s\n",size2-size1);

    output :
    176
    203
    230
    257
    284
    311

    my dought is fprintf returning characters including space?
    what is the return value of ftell ..bytes ?
    but the way iam writting into file is

    2007-10-10;2:10:26 45 100
    2007-10-10;2:10:27 145 100
    2007-10-10;2:10:28 245 100

    if fprintf returning chars means...by summing all the returns we can find the total length of the file.isn't it !

  3. #18
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    >my dought is fprintf returning characters including space?
    Yes it does

    >what is the return value of ftell ..bytes ?
    Total size of the file from start to the current postion of the file pointer in the file. The ftell returns the value in bytes

    >if fprintf returning chars means...by summing all the returns we can find the total length of the file.isn't it !
    But what about '\n' char as mentioned before it might take 2 bytes on some machines.

    ssharish2005

  4. #19
    Registered User
    Join Date
    Jul 2007
    Location
    Hyderabad
    Posts
    35
    yes "\n" including in file......

  5. #20
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Whilst fprintf(fp,"hello\n"); would return 6, the number of bytes written to the file could be more (or less) depending on how the OS chooses to implement end of line translations (say \n becomes \r\n)
    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. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM