Jump to content

I Need Some Motivation...


Recommended Posts

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

Actually, the Min-GW version of GCC(Minimal GNU for Windows GNU C Compiler, if you're wondering).

EDIT: And how do you use that K&R Rand() function?

506552[/snapback]

 

(root|bone)/usr/local/etc/rc.d# man 3 rand

RAND(3)                FreeBSD Library Functions Manual                RAND(3)

 

NAME

    rand, srand, rand_r -- bad random number generator

 

LIBRARY

    Standard C Library (libc, -lc)

 

SYNOPSIS

    #include <stdlib.h>

 

    void

    srand(unsigned seed);

 

    int

    rand(void);

 

    int

    rand_r(unsigned *ctx);

 

DESCRIPTION

    These interfaces are obsoleted by random(3).

 

    The rand() function computes a sequence of pseudo-random integers in the

    range of 0 to RAND_MAX (as defined by the header file <stdlib.h>).

 

    The srand() function sets its argument seed as the seed for a new

    sequence of pseudo-random numbers to be returned by rand().  These

    sequences are repeatable by calling srand() with the same seed value.

 

    If no seed value is provided, the functions are automatically seeded with

    a value of 1.

 

    rand_r() provides the same functionality as rand().  A pointer to the

    context value ctx must be supplied by the caller.

 

SEE ALSO

    random(3)

 

STANDARDS

    The rand() and srand() functions conform to ISO/IEC 9899:1990

    (``ISO C90'').

 

    The rand_r() function is as proposed in the POSIX.4a Draft #6 document.

 

FreeBSD 4.11                    May 25, 1999                    FreeBSD 4.11

 

So..

 

srand(time(NULL));
rand() % 10;

 

Would be random numbers between 0 and 9. If you wanted 1 to 10 then, (rand() % 10) + 1;

Share this post


Link to post
Share on other sites

Ah... I'll work on making sense of that when I'm not nine-eigthes asleep.

506631[/snapback]

 

:lol: i've been being a code monkey all day, updating my sig.

 

I hacked up (stole lots of code from) the lovely unix tool called `top` to make me a program which only outputs the total cpu usage, then hacked me up a C program which connects to mysql, takes the output of my hacked up cpu usage program via a pipe and finally sticks that number in the database.... then when my sig updates every hour it reads the cpu usage stuffs stored in the database and draws a graph :) Cept it's drawing backwards because mysql is poo and it wont lemme do my subselect.

 

Much fun!

Share this post


Link to post
Share on other sites

Sure, I'll make a...

 

 

 

Put in a number and see what memory address it's in game!

 

 

EDIT: Do I win?

 

/*Put-in-a-number-and-see-what-address-it's-in Game */
/** (c)Sam Tootell, Nebul-X **/

#include <stdio.h>
#include <stdlib.h>

int inputNumbar;

int main(void) {
   
   printf("Enter a numbar!");
   scanf(&inputNumbar);
   
   printf("%d is the address!\n\n\n", &inputNumbar);
   
   system("pause");
   
   return 0;

}

Share this post


Link to post
Share on other sites

lol.

 

If you're actually being serious and trying to do that, you probably want to read it in to a char* and then convert whatever gets put in there to an integer with atoi() :)

 

TOI(3)

 

NAME

    atoi -- convert ASCII string to integer

 

LIBRARY

    Standard C Library (libc, -lc)

 

SYNOPSIS

    #include <stdlib.h>

 

    int

    atoi(const char *nptr);

 

DESCRIPTION

    The atoi() function converts the initial portion of the string pointed to

    by nptr to integer representation.

 

    It is equivalent to:

 

          (int)strtol(nptr, (char **)NULL, 10);

 

SEE ALSO

    atof(3), atol(3), strtod(3), strtol(3), strtoul(3)

 

STANDARDS

    The atoi() function conforms to ISO/IEC 9899:1990 (``ISO C90'').

 

FreeBSD 4.11                    June 4, 1993                    FreeBSD 4.11

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×
×
  • Create New...