Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

ITT we discuss this code

Name: Anonymous 2007-03-19 9:48 ID:T6Q9tY7E

1:

int main(int argc, char **argv) {
    FILE *fp=fopen(argv[1], "r");
    while(feof(fp)) putchar(getc(fp));
    return fcloseall();
}


2:

int main(int argc, char **argv) {
    FILE *fp; // declaring a file pointer
    char c = 0; // allocating 1 byte to store the byte read from file
   
    if(argc != 2) { // checking for arguments
        fprintf(stderr, "Error: usage: %s [file] \r\n", argv[0]); // printing error message
        return 1;
    }
    fp = fopen(argv[1], "rb"); // opening argv[1]
    if(fp == NULL) { // checking for errors
        perror("fopen"); // printing error message
        return 2;
    }
    while(c = getc(fp)) { // reading next char from file
        if(c == EOF) { // checking for end-of-file
            fclose(fp); // closing file
            return 0;
        }
        putchar((int)c); // printing byte
    }
    fclose(fp); // closing file
    return 0;
}


3:

int main(int argc, char **argv) {
   
    FILE *fp;
    char *buffer;
    long filesize;
    if(!(fp = fopen(argv[1], "r"))) {
        perror("fopen");
        return fcloseall();
    }
    fseek(fp, 0, SEEK_END);
    filesize = ftell(fp);
    rewind(fp);
    if(!(buffer = (char*)malloc(filesize+1))) {
        perror("malloc");
        return fcloseall();
    }
    if(fread(buffer, sizeof(char), (size_t)filesize, fp) != filesize) {
        perror("fread");
        goto __exit;
    }
    if(fwrite(buffer, sizeof(char), filesize, stdout) != filesize) {
        perror("fwrite");
        goto __exit;
    }
   
    __exit:
    free(buffer);
    fcloseall();
    return 0;
}

What would you prefer

Name: Anonymous 2007-03-19 13:26 ID:7um4Ga3h

>>7
If the resolution of the SLD_GetTicks() function is low, probably something like 10 ms, you will get an update each 40 ms which is only 25 fps instead of 30 fps. You should use prevTicks -= curTicks to reset the time difference. This way the error accumulates, so you will get an update after 40 ms or 30 ms and the average fps will be 30.

Also it is usually better to use a fixed fps to update the subsystem, for example a physics simulation, but let the graphics update as fast as possible.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List