DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦7df29dde5⟧ TextFile

    Length: 1251 (0x4e3)
    Types: TextFile
    Notes: UNIX file
    Names: »FILE.c«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦2d53db1df⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »frankh/src/FILE.c« 

TextFile

/*
 * test of file access
 */
#include	<stdio.h>

main()
{

char	*fname, *num, *str, c, a;
register int	i, j, cnt;
char 	*itoa();
FILE *f1, *fopen();

	printf("begin test\n");
	fname = "testf.txt";
	num = "        ";
	j = 123;


	if ((f1 = fopen(fname, "w")) == NULL) {
			printf(" No can open\n");
		exit(1);
	}

	num = itoa(j, num);
	printf(" num: %s\n", num);
	stwrite(f1, "This is a test." + 0);
	stwrite(f1, " this is another test\n" + 0);
	stwrite(f1, " And yet another one!\n" + 0);
	fname = " A stringy test!!\n" + 0;
	stwrite(f1, fname);
	printf("fname: %s\n",fname);
	stwrite(f1, num + 0);
	stwrite(f1, fname);
	printf("Close: begin\n");
	fclose(f1);
}

/*
 *  Convert interger to ascii string ( leading zeros )
 *  five places.
 */
char *itoa(in, strng)
unsigned int in;
char *strng;
{
register int i;
unsigned int p;
	p = 10000;
	strng[0] = 32; 		/* lead off with a blank	*/
	for(i = 1; i != 6; ++i) {
		strng[i] = in / p + 0x30;
		in = in - ( in / p ) * p;
		p = p / 10;
	}
	return(strng);
}

/*
 * write a character string to a file.
 *  string terminated with '\000'.
 */
stwrite(fd, strng)
FILE *fd;
char *strng;
{
register int i;

	for (i = 0; strng[i] != 0; ++i)
		if (putc(strng[i], fd) == EOF)
			printf("stwrite: bad write\n");
}