Jump to content

Beginner problem.

Go to solution Solved by elpiop,

The srand function takes an unsigned int as a parameter. You're trying to pass in char *, which is what the error is saying. I think you just need to use 'time(NULL)' instead of ctime(NULL). Ctime converts the time to a character string, when srand() needs just the time as an unsigned int. 

When I try to run this code I get the error: 'void srand(unsigned int)': cannot convert argument 1 from 'char *' to 'unsigned int' 

and under it

 argument of type "char *" is incompatible with parameter of type "unsigned int" 

 

The language I am coding in is C++. 

 

Here's a pastebin link to my code: 

http://pastebin.com/cMBQdDGp

 

(Feel free to criticize as I'm new to coding and I want to learn how to code clean code :D) 

Link to comment
https://linustechtips.com/topic/685554-beginner-problem/
Share on other sites

Link to post
Share on other sites

The srand function takes an unsigned int as a parameter. You're trying to pass in char *, which is what the error is saying. I think you just need to use 'time(NULL)' instead of ctime(NULL). Ctime converts the time to a character string, when srand() needs just the time as an unsigned int. 

Link to comment
https://linustechtips.com/topic/685554-beginner-problem/#findComment-8805282
Share on other sites

Link to post
Share on other sites

15 hours ago, elpiop said:

The srand function takes an unsigned int as a parameter. You're trying to pass in char *, which is what the error is saying. I think you just need to use 'time(NULL)' instead of ctime(NULL). Ctime converts the time to a character string, when srand() needs just the time as an unsigned int. 

Wow. Thank you. I never would've know that c in c time meant character time if you hadn't said anything. 

Link to comment
https://linustechtips.com/topic/685554-beginner-problem/#findComment-8808262
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×