[ create a new paste ] login | about

Link: http://codepad.org/sgXIaOtZ    [ raw code | output | fork ]

C, pasted on Nov 23:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char *argv[])
{
	FILE *fp;
	char buf[80];
	int i, c, sum = 0;
	int src[3] = {0,};
	time_t current;
	struct tm *local;
	char *element[] = {
		"水",
		"鉄",
		"鉛",
		"白金",
		"塩",
		"ペットボトル",
		"モリタポ",
		"木材",
		"段ボール",
		"和紙"
	};

	if ((fp = fopen(*++argv, "r")) == NULL)
	{
		fprintf(stderr, "%s: cant't open %s\n", argv[0], *argv);
		return 1;
	}

	time(&current);
	local = localtime(&current);
	while( (c = fgetc( fp )) != EOF )
	{
		printf( "%c", c );
		sum += c;
	}
	srand(sum + local->tm_wday);

	for (i = 0; i < 3; i++)
		src[i] = (int)(rand()*(10.0)/(1.0+RAND_MAX));

	printf(" は、\n");
	for (i = 0; i < 3; i++)
		printf("%s で出来ています。\n", element[src[i]]);

	fclose(fp);

	return 0;
}


Output:
1
(null): cant't open (null)


Create a new paste based on this one


Comments: