Atheme Misc


Function to strip bad characters out of hostmask (to go with Kuja's VHostOnID)

#include <stdio.h>
#include <string.h>
#include <ctype.h>

char* stripChars(char *string)
{
        //int isalnum(int c) -- True if c is alphanumeric.
        int i,j = 0,size = strlen(string);
        char *result = malloc(sizeof(char) * strlen(string));
       
        for (i = 0; i < size; i ++)
        {
                if (isalnum((int)string[i]))
                {
                        result[j] = string[i];
                        j++;
                }
        }
       
        result[j] = '\0';
        return result;
}


This mallocs a new string, so be sure to free if need be. I didn't want to destroy the actual buffer, because it would seem to me you need it elsewhere..


CategoryAtheme
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki