Thread: Need help on fastest typer game

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    2

    Unhappy Need help on fastest typer game

    I need help on how I could open a file from my code and get the words that are stored in the file 1 by 1 and then display it and that would be the word that would be typed by the player.Example:file name: words.txtcontent: dog cat appleThe code would printType the word:dogthen after the player would type the correct word the next word will appear, in the example: catI'm also thinking on how I could check if the letters typed are correct still don't have much idea thoughHow can I store the word from a file to a string? thanks

  2. #2
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    373
    Quote Originally Posted by Jokkerz View Post
    How can I store the word from a file to a string? thanks
    Check out fgets().

  3. #3
    Registered User
    Join Date
    Mar 2014
    Posts
    14
    Take a look at fread() and fwrite() when it comes to opening files like text files. I believe the linux rule also translates over to windows that you first have to open and close files before you can read or write to them. for opening or closing files take a look at fopen() and fclose(). Keep in mind that these two function's return types are file pointers of type FILE * fp.

    I have only programmed within linux so feel I cannot say for certain that these functions are the best ones in windows.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by Kotik View Post
    Take a look at fread() and fwrite() when it comes to opening files like text files.
    No, fread() and fwrite() are for binary files. fgets, fscanf, fgetc; and fputs, fprintf, fputc are for text files. The OP is referring to text file. You must make sure you open the file in the right mode (binary or text) too, depending on whether you use binary or text file functions.
    Quote Originally Posted by Kotik View Post
    I believe the linux rule also translates over to windows that you first have to open and close files before you can read or write to them.
    That is not a Linux rule. It is a C rule*, you must open a file via fopen (which returns a FILE * for you to use, that maps to the file -- otherwise you have junk in your file object) if you wish to use any of the file functions.
    Quote Originally Posted by Kotik View Post
    for opening or closing files take a look at fopen() and fclose().
    That's actually correct**, but...
    Quote Originally Posted by Kotik View Post
    Keep in mind that these two function's return types are file pointers of type FILE * fp.
    This is not -- at least, most of it is wrong. fclose does not return a FILE *, it returns an int. You could easily find that out by Googling or reading the C standard, a decent textbook, etc. Furthermore, saying FILE * fp is a type is incorrect, as fp is not part of a type declaration, it is an identifier (here, specifically a variable name). The type is simple FILE * or pointer to FILE (or similar).
    Quote Originally Posted by Kotik View Post
    I have only programmed within linux so feel I cannot say for certain that these functions are the best ones in windows.
    They are all standard C functions. Any conforming C implementation will ensure that they exist and work as documented.

    * It's also just a general rule of computers/programming and most other things: you must acquire access to a resources before you make use of it.

    ** There are other ways to get access to a FILE *, to use with functions like fgets. freopen is standard, but the rest are non-standard and usually OS/implementation specific, like fdopen on *nix.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fastest DataBase
    By C_programmer.C in forum C Programming
    Replies: 21
    Last Post: 07-12-2013, 01:52 PM
  2. Fastest Internet Ever?
    By hk_mp5kpdw in forum A Brief History of Cprogramming.com
    Replies: 70
    Last Post: 03-07-2008, 05:10 PM
  3. I'm looking for the fastest!
    By Yarin in forum Windows Programming
    Replies: 4
    Last Post: 11-07-2007, 03:30 PM
  4. Fastest way to do an SDL_BlitSurface?
    By manugarciac in forum C++ Programming
    Replies: 5
    Last Post: 05-04-2007, 05:44 AM
  5. Fastest Display?
    By QuestionC in forum Windows Programming
    Replies: 1
    Last Post: 07-05-2002, 01:15 PM