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

Shit in C

Name: Anonymous 2009-02-25 10:09

I'm trying to set the contents of a string based on what random number is generated by my srand.

dice = rand() % 10 + 1;

if ( dice = 1 )
word[20] = "Success";

^-- this shit doesn't work, though.

tl;dr. I want my "dice rolls" to generate a random number, random number corresponds to a pre-set word, and the preset word to be printed.

I'm probably going about it the wrong way. Suggestions from experts?

Name: Anonymous 2011-12-30 17:53

You can't do this:
char array[20];

array = "string";

You can do
char array[] = "string";
But you can't assign a string to an array that already exists:
[quote]$ cat >tmp.c
int main()     
{
    char array[20];
    array = "string";
    return 0;
}

$ cc tmp.c
tmp.c: In function ‘main’:
tmp.c:4:8: error: incompatible types when assigning to type ‘char[20]’ from type ‘char *’[/quote]

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