Anope IRC Services

Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: [Problem] char* to int  (Read 3183 times)

0 Members and 1 Guest are viewing this topic.

Blue_Key

  • Guest
[Problem] char* to int
« on: May 27, 2006, 05:03:12 PM »

How i can pass char* to int ?

i make this but services crash...


Quote

char *argv[5];
int max_join_time = 3;

... code ...

        if ((argv[1] != NULL) && (isdigit(argv[1]))) {
           max_join_time = atoi(argv[1]);
        }

Logged

Dmitry

  • Guest
(No subject)
« Reply #1 on: May 27, 2006, 08:06:01 PM »

Write function:
#include<stdlib.h>

    int StringToInt(char *str)
      {
          char c;
         
          int i,digit=0;
          int k=1;
 
          for(i=strlen(str);i>0;i--)
            {
              digit+=(str-'0')*k;
              k*=10;
            };
         
        return digit;  
     }

This function convert String to unsigned Integer.  WARNING this function not check input argument
Logged

Pieter Bootsma

  • Team
  • *
  • Offline Offline
  • Posts: 189
    • http://geniusdex.net/
(No subject)
« Reply #2 on: May 27, 2006, 09:27:51 PM »

There is a C function (on POSIX-systems, which anope is designed for) which converts strings to integers: http://www.die.net/doc/linux/man/man3/strtol.3.html
Logged

Blue_Key

  • Guest
(No subject)
« Reply #3 on: May 27, 2006, 10:24:50 PM »

nice it's good, thank :)
Logged
Pages: [1]   Go Up