All pastes #289938 Raw Edit

Mine

public c v1 · immutable
#289938 ·published 2006-12-23 15:34 UTC
rendered paste body
#include <stdio.h>#include <string.h>#include <stdlib.h>struct spawnArea{	int 	objID;	int 	mapID;	int 	modelID;	int 	quantity;	int 	respawnTime;	char* 	points;	int 	range;};voidcalculate_center_coord (char* coords, int* xCoord, int* yCoord){	int 	count;	int 	x;	int 	y;	char* 	pair;	static const char serialFormat[] = "%i,%i";		pair = strtok (coords, "|");	while (pair != NULL)	{				if (2 != sscanf (pair, serialFormat, &x, &y))		{			printf ("Unable to scan co-ordinate pair '%s'\n", pair);			break;		};				*xCoord += x;		*yCoord += y;				pair 	= strtok (NULL, "|");		count++;	};			*xCoord = (int) (((float) *xCoord / count) + 0.5);	*yCoord = (int) (((float) *yCoord / count) + 0.5);};intmain (int argc, char** argv){	FILE*				SQLFile;	struct spawnArea	record;	char*				lineBuffer;	int					lineNumber 		= 0;	int					scanned 		= 0;		int					xCoord			= 0;	int					yCoord			= 0;		static const char 	SQLFormat[] 	= \		"INSERT INTO `list_spawnareas` VALUES " \		"('%i', '%i', '%i', '%i', '%i', '%i', '%i|%s '%i');";	SQLFile			= fopen("advsql.sql", "r");	lineBuffer		= malloc(1024);	record.points 	= malloc(512);	while (!feof (SQLFile)) 	{		if (NULL == fgets (lineBuffer, 1024, SQLFile))		{ 			puts ("Failed to read file");			break;		}				{			int discard1;			int discard2; 						scanned = sscanf				(lineBuffer, SQLFormat, &discard1, &record.objID, &record.mapID, 				&record.modelID, &record.quantity, &record.respawnTime, &discard2,				record.points, &record.range);		}					if (scanned != 9)		{ 			printf ("Failed to scan line #%i:\n", lineNumber);			printf ("Line 0 reads: '%s'\n", lineBuffer);			break; 		}				calculate_center_coord (record.points, &xCoord, &yCoord);				printf			("INSERT INTO `spawn` (`objID`, `mapID`, `modelID`, `quantity`, "\			"`respawnTime`, `xCoord`, `yCoord`, `range`) VALUES(NULL, %i, %i, "\			"%i, %i, %i, %i, %i, %i);\n",			record.objID, record.mapID, record.modelID, record.quantity, 			record.respawnTime, xCoord, yCoord, record.range); 				lineNumber++;	};		fclose 	(SQLFile);	free 	(lineBuffer);	free	(record.points);	exit	(0);};