Thread: Compiler won't take #<stdlib.h>

  1. #1
    Novice.
    Join Date
    Oct 2005
    Posts
    88

    Compiler won't take #<stdlib.h>

    I'm trying to make a guess the number program, and I've come up with this:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
     int a;
     int b;
     b=randomize(10);
     printf("%d\n",b);
     printf("Enter number: ");
     scanf("%d", &a);
     while (a != b)
              {
               printf("Wrong! Try again: ");
               scanf("%d", &a);
              }
    printf("Congratulations! You guessed right!");
    getchar();
    getchar();
    }
    However, when I compile and I click the "linker" tab in the bottom of the screen I see the following messages:
    Code:
    d:\documents and settings\pim\mijn documenten\c\guessnum.o(.text+0x75):guessnum.c: undefined reference to `randomize'
    I'm using the Bloodshed Dev C++ compiler, version 4.

    Could anyone tell me what I have done wrong here?

    Thank You.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    isn't the function called rand()?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Compiler won't take #<stdlib.h>
    Which has nothing to do with the problem.

    Your problem is a linker error message, and the real reason for the problem is randomize isn't a standard function.

    Your choices are
    srand() - to seed the generator
    rand() - to get the next pseudo-random value
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Novice.
    Join Date
    Oct 2005
    Posts
    88
    I was using this website.
    Anyway did I understand correctly that: srand will take a new semirandom value and "give" that to rand()? And how would I use srand() and rand() together? I don't think this page is very clear.
    Last edited by omnificient; 12-11-2007 at 01:29 PM.

  5. #5
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Code:
    /*seed the number*/
    srand((unsigned)time(0));
    
    /*create a random number*/
    int num = rand() &#37; 5 + 1;
    Double Helix STL

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Looks like that page was using Turbo C, which apparently has a lot of non-standard crap in it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM