• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

can someone please tell me what I am doing wrong here?

BirdDad

Golden Member
I have this program
Code:
#include <stdio.h>
int main ()
{

    FILE *pfile;
    FILE *pfile2;
    FILE *pfile3;
    FILE *pfile4;

    unsigned long long filesize = 0;
    unsigned long long counter;
    char filename[100] = "";

    printf("ENTER [path] file name.ext:\n");
    gets(filename);

    pfile = fopen (filename,"rb");

    if (pfile==NULL)
        perror ("Error");
    else
    {
        fseeko64 (pfile, 0, SEEK_END);
        filesize = ftello64 (pfile);
        counter = filesize;
        fclose (pfile);
        printf ("File:\n%s\ncontains %I64d bytes:\n", filename, filesize);
        while (counter > 0)
            printf (" \n counter is at %I64d of %I64d" ,counter,filesize);
            counter = counter -8;
    }
    return 0;
}
it keeps on giving the same number without subtracting the 8 each time
where am I messing up?
 
to add on what Dave said, if you don't put brackets after conditionals, then it will just interpret the next line as what to do when the conditional is met and continue on.

so basically what you have is the same as the following:

Code:
while (counter > 0) {
    printf (" \n counter is at %I64d of %I64d" ,counter,filesize);
}
counter = counter -8;

you want to move the counter logic up inside that closing bracket.

also your program SHOULD be giving you an infinite loop of that print f statement once it gets into that while loop, because counter is never getting smaller.
 
Back
Top