All pastes #674887 Raw Edit

Untitled

public c v1 · immutable
#674887 ·published 2007-08-29 16:40 UTC
rendered paste body
#include <stdio.h>struct IRCName{ char *username, *hostname, *host; };IRCName* parseIRCName(char *full);int main(){    IRCName *user;    char *string = "bananafly!~uejcpo@81-229-120-21-no28.tcbn.telia.com";    for(int i=0;i<1000000;i++){        user = parseIRCName(string);        free(user->hostname);        free(user->username);        free(user->host);        free(user);    }    puts("Done!");    getc(stdin);    return 0;}IRCName* parseIRCName(char *full){    IRCName *ret;    ret = malloc(sizeof(IRCName));    char *p, *tmp;    int *len;        tmp = malloc(sizeof(char)*255);    for(p=full;*p != '!';p++)        tmp[p-full] = *p;    tmp[p-full] = '\0';    len = malloc(sizeof(int));    *len = strlen(tmp);    ret->username = malloc(*len);    strcpy(ret->username, tmp);    free(tmp);        tmp = malloc(sizeof(char)*255);    for(p++;*p != '@';p++)        tmp[p-full-*len-1] = *p;    tmp[p-full-*len-1] = '\0';    ret->hostname = malloc(strlen(tmp));    strcpy(ret->hostname, tmp);    free(tmp);    free(len);        p++;    ret->host = malloc(strlen(p));    strcpy(ret->host, p);    return ret;}