Anope IRC Services

Anope Development => Modules => Topic started by: Blue_Key on May 27, 2006, 05:03:12 PM

Title: [Problem] char* to int
Post by: Blue_Key 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]);
        }

Title:
Post by: Dmitry 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
Title:
Post by: Pieter Bootsma 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
Title:
Post by: Blue_Key on May 27, 2006, 10:24:50 PM
nice it's good, thank :)