Exemple #1
0
char* getstring(const char *f, int len)
{
	FILE *fin = fopen(f, "r");
	char *str = (char *)calloc(len + 1, sizeof(char));
	fgets(str, len + 1, fin);
	clearfile("out.txt");
	sort(str);
	free(str);
	fclose(fin);
	return str;
}
Exemple #2
0
main ( int argc, char *argv[] )
{
    int a;
    char Volba;

    while ( ( Volba = Menu() ) != '5' )
    {
        switch ( Volba )
        {

        case '1':
            system ( "clear" );
            printf ( "Generating please wait...\n\n" );
            genrandom();
            sort();
            printrnd();
            printall();

            printf ( "\n1. Export results to file\n2. Continue\nType choice number: " );
            scanf ( "%d", &a );
            if ( a==1 )
            {
                exptofile();
                printf ( "Exported!" );
                getchar();
                getchar();
            }

            break;

        case '2':
            system ( "clear" );
            printf ( "How many lines do you want? " );
            gennlines();
            break;

        case '3':
            system ( "clear" );
            compare();
            break;
        case '4':
            clearfile();
            printf ( "Done!" );
            getchar();
            getchar();
            break;

        }
    }

    system ( "clear" );
    return 0;
}
Exemple #3
0
program()
{

        var filename=COMMAND.a(2);

        var itemids=erase(COMMAND,1,0,0);
        eraser(itemids,1,0,0);

        var silent=index(ucase(OPTIONS),"S");

        if (not filename or not itemids)
                abort("Syntax is 'delete filename itemid ... (S=Silent)'");

        var file;
        if (not open(filename,file))
                abort(filename^" file does not exist.");

        var sep=0;
        var posn=1;
        var ndeleted=0;
        do {
                var itemid=remove(itemids,posn,sep);

                if (itemid=="*") {
                        clearfile(file);
                        if (not silent)
                                printl("All records deleted");
                        stop();
                }

                if (deleterecord(file,itemid))
                        ++ndeleted;
                else if (not silent)
                        printl(quote(itemid)^" does not exist.");
        } while (sep);

        if (not silent)
                printl(ndeleted^" record(s) deleted.");
}
function main() {
	printl("testnaturalsort says 'Hello World!'");

	var tempfilename="tempsortfile";
	tempfilename.outputl("tempfilename=");

	var dicttempfilename="dict_"^tempfilename;
	dicttempfilename.outputl("dicttempfilename=");

	deletefile(tempfilename);
	deletefile(dicttempfilename);

	//let everything be one transaction
	//with automatic rollback at close of program ^_^
	//and anyway is REQUIRED for the select() command
	begintrans();

	if (not createfile(tempfilename))
		abort("cant create "^tempfilename);
	if (not createfile(dicttempfilename))
		abort("cant create "^dicttempfilename);
	clearfile(tempfilename);
	clearfile(dicttempfilename);

	var tempfile;
	if (not open(tempfilename,tempfile))
		abort("cannot open "^tempfilename);

	if (not write(
	"F" _FM_
	"0" _FM_
	"ID" _FM_
	_FM_
	_FM_
	_FM_
	_FM_
	_FM_
	"R" _FM_
	"20", dicttempfilename, "ID"))
		abort("cannot write "^dicttempfilename^" ID");

	//var ndigits=9;
	//var nzeros=25;
	var ndigits=3;
	var nzeros=3;

	//create records backwards to test sort
	var ii,jj;
	for (ii=ndigits;ii>=0;--ii)
		for (jj=nzeros;jj>=0;--jj) {
			var key="x"^ii^str("0",jj);
			write("junk",tempfile,key.outputl("key="));
		}
	//read sorted records forwards to check numbers
	if (not tempfile.select("by ID")) {
		tempfile.getlasterror().logputl("lasterror=");
		abort("problem sorting file");
	}
	var key;
	//while (tempfile.readnext(key)) {
	while (tempfile.readnext(key)) {
		printl(key);
	}
	//rely on automatic rollback to rollback all work done
	//deletefile(tempfilename);
	committrans();

	return 0;
}
Exemple #5
0
int main()
{
	clearfile();
	fun(13);
	return 0;
}