What's wrong with this code?

This is a discussion on What's wrong with this code? within the C Programming forums, part of the General Programming Boards category; I'm kind of new to programming, anyway I wanted to write a program to count the size of a file. ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    8

    What's wrong with this code?

    I'm kind of new to programming, anyway I wanted to write a program to count the size of a file. It detects the end of file earlier than expected.
    I can't seem to find something wrong.Please take a look and tell me.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    #define ARXEIO1 "C:SIZE_TO_FIND.DAT"

    void synartisi_1(int *bytes,char *xar,FILE *arxeio);

    int main(void)
    {

    FILE *arxeio1;
    char xar;
    int bytes = 0;
    int r = 0;

    arxeio1 = fopen(ARXEIO1,"r");

    synartisi_1(&bytes,&xar,arxeio1);
    while ( feof(arxeio1) == 0 )
    {
    synartisi_1(&bytes,&xar,arxeio1);
    }

    fclose(arxeio1);
    return 0;

    }



    void synartisi_1(int *bytes,char *xar,FILE *arxeio)
    {

    (*bytes)++;
    fgetc(arxeio);
    if ( (*bytes)%100 == 0 )
    {
    printf("\nUntil now %d bytes %.3f Kb %.3f Mb", (*bytes) , ((*bytes)/1024.0) , (((*bytes)/1024.0)/1024.0) );
    }

    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    A few things for you to read:
    << !! Posting Code? Read this First !! >>
    http://faq.cprogramming.com/cgi-bin/...&id=1043284351
    http://www.eskimo.com/~scs/C-faq/q19.12.html

    You may want to open the file in binary mode ("rb").

    Also, check the return code from fopen() before using it.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    8
    I didn't know about the code tags, and I also
    didn't think that the title of my thread was wrong.
    I will from now on, try to apply these things.
    Thank you very much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 07:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 09:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 05:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 01:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21