18 Feb, 2009, boblinski wrote in the 1st comment:
Votes: 0
Hi there, I'm trying to redo my do_score to display things a little different..

Displaying my weight_carried/max_weight is causing me a few problems..

This is what I got:
sprintf (buf, "Weight: %d\n\r",
get_carry_weight(ch), can_carry_w (ch));

send_to_char (buf, ch);


These are the errors:
$ make
gcc -Wall -O -ggdb -DNOCRYPT -DQMFIXES -c -o obj/act_info.o act_info.c
act_info.c: In function `do_score':
act_info.c:1579: warning: int format, long int arg (arg 3)
act_info.c:1579: warning: too many arguments for format
act_info.c:1579: warning: int format, long int arg (arg 3)
act_info.c:1579: warning: too many arguments for format
rm -f rom


Note- line 1579 refers to "get_carry_weight(ch), can_carry_w (ch));"

Thanks in advance :redface:
18 Feb, 2009, Caius wrote in the 2nd comment:
Votes: 0
You need one '%d' per integer argument you pass. You pass two arguments (get_carry_weight and can_carry_w). So you probably want something like:
sprintf( buf, "Weight: %d of max %d\r\n", get_carry_weight( ch ), can_carry_w( ch ) );
18 Feb, 2009, boblinski wrote in the 3rd comment:
Votes: 0
Haha that was silly of me. Okay- I changed it to–

sprintf (buf, "Weight: %d/%d\n\r",
get_carry_weight( ch ), can_carry_w( ch ) );
send_to_char (buf, ch);


This still gives these problems:
$ make
gcc -Wall -O -ggdb -DNOCRYPT -DQMFIXES -c -o obj/act_info.o act_info.c
act_info.c: In function `do_score':
act_info.c:1579: warning: int format, long int arg (arg 3)
act_info.c:1579: warning: int format, long int arg (arg 3)
rm -f rom


Also, when I actually do "score" on the mud… it shows: "Weight: 30/1325".. when the char actually only carries a weight of 3…
18 Feb, 2009, Remcon wrote in the 4th comment:
Votes: 0
Change it to
sprintf (buf, "Weight: %ld/%ld\n\r", get_carry_weight( ch ), can_carry_w( ch ) );
send_to_char (buf, ch);

As for the 30 remove and drop everything and see how its getting that high as you pick it up and put it all back on.
18 Feb, 2009, Hades_Kane wrote in the 5th comment:
Votes: 0
%d = short int
%ld = long int

If you are trying to display a number and the number is a long int but you are trying to display it as %d, you are going to get that error.

Apparently, the number returned by get_carry_weight and can_carry_w are long ints, so that's why it was giving you that.

As far as why the number is spitting out funny, you might take a look at the get_carry_weight function and see if it is set to multiply anything.

If I recall right, a lot of the "weight" stuff in ROM, by default, is either multiplied or divided by a multiple of 10. Is your stock do_score function dividing the result you get when you are displaying weight?
18 Feb, 2009, Skol wrote in the 6th comment:
Votes: 0
Yeah, weights in Rom are 1/10th pounds. In OLC it is etc.
Try wearing nothing, pick up an object that you have built to be say weight 50. (5 lbs)
See the increase, your seeing 1/10th pounds.

A couple of options:
sprintf (buf, "Weight: %ld/%ld\n\r", get_carry_weight( ch )/10, can_carry_w( ch )/10 );
send_to_char (buf, ch);

That one simply 'rounds' it to the nearest pound.

So your 30/1325 would read Weight: 3/132

int gcw, ccw,gcw_dec, ccw_dec;
gcw = get_carry_weight (ch); // get carry in 10th's
ccw = can_carry_w (ch); // can carry in 10th's
gcw_dec = gcw - ((gcw/10) * 10); // get carry decimal left-over
ccw_dec = ccw - ((ccw/10) * 10); // can carry decimal left-over
gcw /= 10; // end get carry in regular pounds
ccw /= 10; // end can carry in regular pounds

// Obviously we don't have to do all of those ints, but this way he can see
// What math we're doing more easily
sprintf (buf, "Weight: %ld.%ld/%ld.%ld\n\r", gcw, gcw_dec, ccw, ccw_dec );
send_to_char (buf, ch);


So your 30/1325 would read Weight: 3.0/132.5

The second way just basically does the number divided by 10 (drops any remainder/decimal), then times 10 to get the full size in 10ths. Original minus that gives the decimal. (Again we could do it all in the sprintf, but I wanted to show the math so to speak).
18 Feb, 2009, boblinski wrote in the 7th comment:
Votes: 0
Okay, thanks for all the help, but I'm still getting the warnings:

What I've got:
sprintf (buf, "Weight: %ld/%ld\n\r", get_carry_weight( ch )/10, can_carry_w( ch )/10 );
send_to_char (buf, ch);


Warnings:
$ make
gcc -Wall -O -ggdb -DNOCRYPT -DQMFIXES -c -o obj/act_info.o act_info.c
act_info.c: In function `do_score':
act_info.c:1578: warning: long int format, int arg (arg 4)
act_info.c:1578: warning: long int format, int arg (arg 4)
rm -f rom
18 Feb, 2009, David Haley wrote in the 8th comment:
Votes: 0
When you add the divide by 10, it becomes an int again; use %d in that case. Or, if you want to force it to be a long int, I think you'd use 10l (10 followed by letter "L"). E.g., get_carry_weight(ch)/10l. I don't remember if the L is upper-case or lower-case.
18 Feb, 2009, boblinski wrote in the 9th comment:
Votes: 0
Could it have something to do with the fact that IMP's can carry like 1000000 pounds?

Also, what is the cut off point between long int and short int? like 3 characters?
18 Feb, 2009, David Haley wrote in the 10th comment:
Votes: 0
It has to do with the data types used to represent the values, not how the values themselves are used. For data type sizes, see this Wikipedia page.

Note that somebody said that "int" is for short ints – this is not really true. An int's exact size is not determined, and can be that of either a short int or long int depending on implementation details (machine platform, etc.). %d is the format specifier to use for generic ints, and %ld is what you use for long ints.
18 Feb, 2009, boblinski wrote in the 11th comment:
Votes: 0
sprintf (buf, "Weight: %ld/%d\n\r",
get_carry_weight( ch )/10, can_carry_w( ch )/10 );
send_to_char (buf, ch);


when I use that.. it works perfect and has no warnings!.. why?

so %ld isn't necessarily used because their is lots of characters in the variable?
18 Feb, 2009, Skol wrote in the 12th comment:
Votes: 0
Short int (or just %d) will 'roll over' after 32,767 (or -32,768), meaning it can be from -32,768 to 32,767.
So, say you use a short int for a character's gold, and they get over 32,767? Their gold then rolls over to a negative and adds in the remainder to that negative number. An unsigned short int is 0-65,535.

Long ints are -2,147,483,648 to 2,147,483,647. (or just 2x that for unsigned, starting from 0).
18 Feb, 2009, elanthis wrote in the 13th comment:
Votes: 0
%ld means long int, %d means int. All there is to it. If you don't understand what the difference is, you might want to pick up an introductory book on C programming. Here's a crappy summary:

C supports several int sizes: char, short int, int, long int, and (in later standards) long long int. The actual meaning of these sizes is _implementation dependent_, so long as they follow a few rules. Basically, on some compilers, int and long int are the exact same thing. On others, int might be 16-bit and long int might be 32-bit. Or int might be 32-bit and long int might be 64-bit.

On standard Intel-compatible 32-bit OSes, char is 8-bit, short is 16-bit, int and long are both 32-bit, and long long int is 64-bit. That is also the setup for 64-bit Windows. On 64-bit Linux/UNIX, long is usually 64-bit instead of 32-bit.

If you tell printf() that you are going to give it a long int (%ld) and you actually pass it an int then you may (on some compilers) get a crash or corruption, because printf tries to read in 64-bits of data when you only gave it 32-bits of data. Likewise, you can get crashes or corrupted output if you try to read a 32-bit int (%d) from a 64-bit value, depending on platform.

So far as the cut-off, it is all about bits (binary digits) and not decimal digits. An 8-bit unsigned int can store a maximum value of 255, for example. It's not a limit like 0-999, but a limit of 0-11111111 (in binary). A quick Google search can explain this far better than I – I think the link David provided is about this stuff (didn't look, but David's a smart guy, figured he'd link to a relevant topic ;)
18 Feb, 2009, David Haley wrote in the 14th comment:
Votes: 0
Skol said:
Short int (or just %d)

%d means int – not short int. (see man 3 printf) Elanthis explained this in more detail so I'll insert his post here. :wink:
18 Feb, 2009, Skol wrote in the 15th comment:
Votes: 0
Heh, no kidding, i spouted off short int after thinking 'not long'.
18 Feb, 2009, Hades_Kane wrote in the 16th comment:
Votes: 0
Skol said:
Heh, no kidding, i spouted off short int after thinking 'not long'.


Easy to do, huh?
18 Feb, 2009, Skol wrote in the 17th comment:
Votes: 0
Hehe, yep yep.
0.0/17