Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, Can anyone advise on how to converting a string of char[15] to int. I try using atoi() but the string is too long to be converted. Regards...
  1. #1
    Just Joined!
    Join Date
    Feb 2007
    Posts
    14

    Converting string to int

    Hi,

    Can anyone advise on how to converting a string of char[15] to int. I try using atoi() but the string is too long to be converted.

    Regards

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Use a long variable and convert it with the atol() function.

    Regards

  3. #3
    Just Joined!
    Join Date
    Feb 2007
    Posts
    14
    Hi,

    I try atol but it seem that my string is too long cause atol only support up to a length of 11. So when i try to do the following, it return invalid data.

    long int li;
    char tmp[16];
    strcpy(tmp,"99999999999");
    ul = atol(tmp); // return 1410065407

    regards

  4. #4
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Define your variable as "unsigned long long" and try te functions strtoll() or strtoug(), Google for examples.

    Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...