Thread: startup help for my new project

  1. #1
    Registered User dune911's Avatar
    Join Date
    Sep 2001

    Smile startup help for my new project

    hi there and thanks for reading (and be sure to read my signature)

    i want to program a random-name-generator. the main program will have an option to print out one, five or then random names out of my database on the screen. the program will run in the dos-console in windows. i use djgpp to compile and dev-c++ to write my sourcecode. i will use plain c to program the generator.

    in the beginning the database will include 20 or 30 names, just for testing out the program functions (random 1, 5, 10).

    my two problems are:

    1) i don't know which is the best way to write the names in the database? i will write them myself, and it must be included in the program so there can be no harm from 'outside'. i need a way to write the names in my database so the program can read out the names 'best'. can you help me with this?

    2) i am not sure how to program the random 1, 5, and 10 functions. any ideas?

    some 'theoretical' hints will help me thank you in advance (be sure to read my signature)

  2. #2
    Registered User
    Join Date
    Dec 2001
    I would suggest you to store the name in lines, something like this:


    so it's easy to read the names, because you just have to call fgets and eliminate the '\n'

    what exactly is your problem with the random function? you will need srand() to initialize and call rand() eacht time you want a random number...
    Hope you don't mind my bad english, I'm Austrian!

  3. #3
    Registered User dune911's Avatar
    Join Date
    Sep 2001
    i want to include the name-database as *.c file in my program. how does it have to look like, so my program can read out each single name best?

    my current problem with the random-function is, that i've never used it before...

    i am not sure of the way to store and read the data... that's my problem with this program...

    thanks for your help

  4. #4
    Code Warrior
    Join Date
    Nov 2001


    Example for the random function:

    # include <stdlib.h> // for command "random"
    # include <time.h> // for command "randomize"

    int generate;

    generate = random(10); // this will randomize numbers between 0 and 10

    Practical use:

    You write the program like that ....

    Each name you write in every single line. So, you use random function in that way that you count all the lines that you're file has (generate = random(all_lines)).

    With reading and writing I suggest that you use pointers and a structure.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  5. #5
    Registered User dune911's Avatar
    Join Date
    Sep 2001
    ok thanks
    i think i know how to do it, now...
    (thanks for the random funtion)

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    database data does not belong in #include files!

    functions, structure declarations, #defines, and other similars, yes, but data should be stored in text or binary files which are opened with fopen(), read with fread(binary), fgets(text), fscanf(text, I think). Write them back to these files using fwrite, fputs, fprintf.

    #including files is for compilation, not storage of data.

  7. #7
    Registered User dune911's Avatar
    Join Date
    Sep 2001
    can you tell me how to read data out of a file?



    how can my program access a name out of this list (random) and print it out on the screen? only one list, only one name (random).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM