All pastes #908242 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-02-18 06:53 UTC
rendered paste body
#include <string.h>

#define BSZ 4096

struct s_nm{

	char *first;
	char *family;
	char *email;
	struct s_nm *next;
	int taken;
	
};

typedef struct s_nm s_nm;

typedef struct{
	char* c[5];
} u_nm;


int main(){

	char cb[BSZ], *tcb;
	s_nm name[150]; // how many friends u got?
	s_nm *st;
	
	int ct_nm = 0;
	int it, is, icr, icr_flap;

	if((it = read(0,cb,BSZ)) > 0){
		icr = 0; icr_flap = 1;
		for(tcb=cb; tcb < cb + it; tcb++){
			switch(*tcb){
				case ' ':
				case '\t':
					icr = ++icr_flap==1 ? icr+1 : icr;
					*tcb = 0;
					continue;
				case '<':
					*tcb=0;
					name[ct_nm++].email = ++tcb;
					icr_flap=0;
					while(tcb < cb + it && *++tcb != '\n'){
						if(*tcb == '>')
							icr_flap++;
						*tcb = icr_flap > 0 ? 0 : *tcb;
					}
					*tcb=0;
					icr = 0;
					icr_flap=1;
					continue;
				default:
					if(icr_flap > 0){
						icr_flap = 0;
						((u_nm*)name+ct_nm)->c[icr] = tcb;
					}
			}
		}
	}
	
	if(it == -1)
		perror("ssanta"),exit(1);
	
	for(it=0;it<ct_nm;it++){
		printf("f:%s g:%s e:%s\n",name[it].first,name[it].family,name[it].email);
		name[it].taken = 0;
		name[it].next = 0;
	}
	
	for(it=0;it<ct_nm;it++){
		for(is=ct_nm-1;is>=0;is--){
			if(name[is].taken)
				continue;
			if(strcmp(name[it].family,name[is].family)){
				name[is].taken = 1;
				name[it].next = name + is;
				break;
			}
		}
	}
	
	/*for(it=0;it<ct_nm;it++){
		st=name + it;
		while(st->next != NULL){
			printf("%s -> ",st->first);
			st = st -> next; 
		}
		printf("%s\n",st->first);
	}*/
	
	for(it=0;it<ct_nm;it++)
		printf("%s gives to %s\n",name[it].first,name[it].next->first);
		
	return 0;

}