Online C/C++ Reference

cmpeters

n00b
Joined
Dec 2, 2006
Messages
17
Does anyone know a website that has a good and thorough reference of standard functions and libraries in C/C++? Or a good suggestion for a reference book? Currently I have "Absolute Beginners Guide to C" but it doesn't seem very good. The majority of the books content has been discussed in more detail by my professor in class.

I seem to get stuck with built-in c functions. Currently I'm trying to find the length of an input value of type unsigned long. Is there a built in function for this, because strlen doesn't seem to work? Do I need to put the input value into a string before I can find its length? If I remember correctly I must define the length of a string at compile time, so do I need to set its length to the maximum length string on a solaris system? The maximum value of an unsigned long is 4294967295.

I really don't have a firm grasp on stuff like this, any suggestions of books/websites to read so I can better understand input/output, data manipulation, and other important concepts? My notes just don't fill the gap.

Thanks
 
I just realized that I'm confusing strings with arrays. I'm thinking that I should put the input integer into an array.

What I need to do is compare each digit of the integer with the preceeding digits.
 
I'd use the sizeof operator; sizeof(unsigned long). But it seems like you might be trying to find the length of a string; in that case, the type isn't unsigned long.

Do you want the maximum length as formatted as a base-10 integer? Or the maximum length in bytes?

I use MSDN for C++ functions all the time. If you're using *nix, I'd see what man pages are available because you're probably best off with documentation that matches your tool set and target platform.

There was a C++ book thread recently in the forum. If you're getting stuck figuring out which function to use for a certain goal, you might try the C/C++ cookbook from O'Reilly, ISBN 0596007612.
 
What I need to do is compare each digit of the integer with the preceeding digits.
And you're talking about base-10 digits, then? I'd use itoa() to convert the integer to a string, then party on each character in the resulting string array.
 
Thanks, I'll read that thread.

I have to write my programs to compile on a Solaris server with gcc. Not sure what version of Solaris or gcc they have.

The input value from the user has to be a non-negative integer that can be as large as the maximum value of type unsigned long available on the system.

I need to take an input value and convert it to a look and say value. Rather than explain I'll just show examples.

Input ---> Output
234447 --> 12133417
Reads as one (2), one (3), three (4s), and one (7).

49982331 --> 142918122311
Reads as one (4), two (9s), one (8), one (2), two (3s), one (1).


My thought on how to solve this it to take the input value and put it into an array. Then start with the left-most digit which would be array[0] and compare it with array[1] if they are equal, then compare with array[2] and so on. When array[0] does not equal the next array value I would output the "look and say" number with the integer value at array[0]. Continue this in a loop. Using a counter so I know what to preface each integer value with.

Would I need a second array to put these values in? Or would it be better to create a string and just concatenate each value?
 
I'm a tad fuzzy on what you're asking, but I think you're wanting to simply count how many digits there are in a number, correct?

I think you're going to need to cast (or convert one data type to another) the numeric value into a string to use the strlen() function. Check this out, I think its a bit tricker to go from int to string.

You could also solve this mathematically with a loop of some sort. Each decimal place is one power of ten greater than the last, right? So...if you successively divide your numbers by a power of ten and stop the loop once the product is less than 1, you could maybe count how many times the loop has completed? Little ugly but just typing this from a bustling cafeteria...haven't used C++ in a bit so I'm rusty.
 
I was thinking that knowing the number of digits in the input integer would be useful to know, because then I would know how long to iterate a loop. Not sure if its necessary though.
 
If I was doing this problem and someone gave me an unsigned long, I'd convert it to a string with itoa() (or whatever platform-specific version worked on unsigned longs instead of just ints).

Then, given that string, I'd start at the first character, looking for runs of characters. When a run ended, I'd add the length of the run and the number I found in the run. The string ends when then character I'm looking at has the value 0 (which is different than "0").

If I could, I'd just generate output with printf(). If I had to store the output someplace else, I'd make a string buffer exactly twice as long as the character representation of the longest integer. You can find this length at compile time by working it out with a calculator. If you really must have something that's dynamic for any platform, you can find the length by getting the ceiling of the base10-log of ULONG_MAX, then adding one.
 
Back
Top