All pastes #621767 Raw Edit

Miscellany

public c v1 · immutable
·published 2007-07-16 11:59 UTC
rendered paste body
#include <tigcclib.h>#define CR				'\r'#define LF				'\n'#define LineMax			601#define FileDelimiter	' '#define CFileDelimiter	" "#define BT_OK 1#define BT_NONE 1void _main(){	FILE *fsys;	char *mounted = "\\sidetext\\fsys2";	char *buf = malloc(LineMax);	char *filename = "\\math\\exercice\\limites";	char *realval = malloc(LineMax);	unsigned short isDiscovered = 0;	//First we look for the file system config file	fsys = fopen(mounted, "rw");	if(!fsys)		DlgMessage("error", "opening fsys", BT_OK, BT_NONE);	//Get each line, one by one and wheck if it does correspond to filename	while(fgets(buf, LineMax, fsys))	{		if(!isDiscovered) //If !isDiscovered, file will be empty			isDiscovered = 2;		if(buf[strspn(buf, filename)] == FileDelimiter) //If filename found, exit of the loop		{			isDiscovered = 1;			break;		}	} //If not discovered, buf = last line of the file	rewind(fsys);	buf[strcspn(buf, "\n")] = '\0'; //Delete new line character for more safety	strtok(buf, CFileDelimiter);	realval = strtok(NULL, CFileDelimiter);	if(!isDiscovered)	{		//Fill the file		char *final = malloc(strlen(filename)+3);		sprintf(final, "%s%s%s\n", filename, CFileDelimiter, "0");		final[strcspn(final, "\n")+1] = '\0';		if(fputs(final, fsys) == EOF)			DlgMessage(final, final, BT_OK, BT_NONE);	}	fclose(fsys);	free(buf);}