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

Pages: 1-

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 10:16 ID:7um4Ga3h

cp

Name: Anonymous 2007-03-19 10:28 ID:R/2PX6Oy

ITT, we use an ugly coding style.

Fix'd

Name: Anonymous 2007-03-19 10:49 ID:IZtiID++

#!/bin/sh

cat $@

Name: Anonymous 2007-03-19 11:03 ID:GbseqyET

module Main where
import System.Environment (getArgs)

main = getArgs >>= \(f:_) -> readFile f >>= putStr

Name: Anonymous 2007-03-19 11:31 ID:EeHeKKDx

K & R bitches

Name: Anonymous 2007-03-19 12:00 ID:nIlMuqvl

inline int gameLoop()
{
 input userInput;
 keyState& theKeyState = userInput.theKeyState;

 /* Time values for frame rate throttling. */
 int prevTicks = 0, curTicks = 0;
 int ticksDifference = 0;
 int framesPerSecond = 30; /* desired frame rate (fps) */
 int updateTime = (1000 / framesPerSecond); /* update frame after this many milli-seconds */

    while (theKeyState.quit == false)
    {
     curTicks = SDL_GetTicks();
     ticksDifference = curTicks - prevTicks;
     userInput.updateState(); /* Grab user input */

        if (ticksDifference >= updateTime)
        {
         // Update subsystem and graphics subsystem goes here!

         prevTicks = curTicks; // reset the time difference
         theKeyState.manualReset(); // reset keys that must be manually reset
        }
    }
 return 0;
}

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.

Name: Anonymous 2007-03-19 17:48 ID:nIlMuqvl

>>8
Thanks man. I'm working on my first game and those pointers definately help.

Name: Anonymous 2007-03-19 19:26 ID:zxMSZcdG

>>1
All versions suck due to various reasons.

Name: Anonymous 2007-03-20 8:50 ID:yKLQPdVi

>>10
explain

Name: Anonymous 2009-01-14 12:44

LISP

Name: Anonymous 2009-02-25 7:00


Salesman talked to Mel   as did the   Big Boss and.

Name: Anonymous 2010-11-02 19:49

Name: Sgt.Kabu끆憟kiman䧮满 2012-05-28 23:40

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

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