ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a problem with data type conversions. I have a variable
unsigned int ipv4;
I pull information out of a MySQL database, which is stored as int(11) unsigned. You'd think they would be compatible. I retrieve a record from the table and include the column that will be stored in ipv4. It is the first column, so gets read as row[ 0 ]. In the database table, I see that the number is stored as 2479501685, which is correct. row[ 0 ] is a pointer to char, however, and when I try this:
ipv4 = atoi( row[ 0 ] );
then ipv4 comes out as 2147483647.
Actually, row[ 0 ] is one element of a MYSQL_ROW type, which, according to the MySQL C API, is "currently implemented as an array of counted byte strings". So I am assuming that one element of row can be treated as char*, which has always worked in the past.
I looked for a function like atoi() specifically for string-to-unsigned-int but found nothing.
What am I missing? Shouldn't atoi() successfully convert string to unsigned int?
Maybe I wasn't clear. I am string to convert a string to an unsigned int, so sprintf() isn't going to work.
I have tried the C functions atoi() and atol() and neither of them are working correctly. The number is being stored in the mysql table as int(11) unsigned and shows up as 2479501685. When I fetch the row with that as the first field, I use
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.