#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "socklib.h"
#include "pullers.h"

#define WWWHOST		"www.32bitsonline.com"
#define REQUEST		"GET /latest_feature.txt\r\n"

int main(void) {
	FILE *fp;
	char rx[256];
	tArticle a;
	FILE *netin,*netout;

	if(!fpopensocket(WWWHOST,80,30,&netin,&netout)) {
		fprintf(stderr,"Error on connect.\n");
		exit(1);
	}

	fprintf(netout,REQUEST);
	fflush(netout);

	fp=fopen(_32BITDATA,"wb");

	/* now read the records */
	while(fgets_strip(rx,255,netin)) {
		strncpy(a.title,rx,255);
		if(!fgets_strip(a.time,255,netin)) break;
		fgets_strip(a.link,255,netin);
		fgets(rx,255,netin); /* skip description */
		fwrite(&a,sizeof(a),1,fp);
	}

	fclose(netin); fclose(netout);

	fclose(fp);

	return(0);
}
