First, why do you say it's not working? Is it a compile error? What's the compiler's error message? Is it a runtime error? How do you know it's handling it incorrectly? Are you displaying the value after the operation and it's not what you expect?
Need more clarity on what the problem is.
What you've given is not actually doing division. You use a backslash ( \ ) as opposed to a forward slash ( / ) in the statement. A forward slash is used for division. A backslash is used to escape a character.
Second, what you have should cast the variable correctly. If not, I would suggest multiplying the return values by 1.0. Such as this:
Code:
d = (1.0 * strlen(str)) / (1.0 * cols);
Technically, you only need to multiply one operand by 1.0, but it doesn't hurt to do both.
Regardless, the typecasting you used originally should work.