All pastes #64570 Raw Edit

Miscellany

public text v1 · immutable
#64570 ·published 2006-06-11 22:13 UTC
rendered paste body
int
main() {
	char				*html_buf, *buf, **tokens;
	const char 		delimiters[] = " ";
	int					cnt, num_of_str;
	cnt = num_of_str = 0;
	
	if ( (html_buf = malloc(BUF_APP_Q)) == NULL)
		err_sys("malloc error");
	
	if ( (buf = malloc(BUF_SIZE)) == NULL) {
		err_sys("malloc error");
	}

	strcpy(html_buf, "tirini  ta ta keke ");
	strcpy(buf, strtok(html_buf, delimiters));
	
	while (buf != NULL)
	{
		if(cnt == 0) {
			if( (tokens = malloc(sizeof(char *))) == NULL)
				err_sys("malloc error");
			++num_of_str;
		}
		else {		
			if( ( tokens = realloc(tokens, ((++num_of_str) * sizeof(char *))) )== NULL )
				err_sys("realloc error");
		}
		if( ( tokens[cnt] = malloc(strlen(buf) + sizeof(char)) ) == NULL )
			err_sys("malloc error");
		strcpy(tokens[cnt], buf);
		strcpy(buf, strtok(NULL, delimiters));
		++cnt;
	}
exit(0);
}