C 语言生成生日字典

生成一个生日字典,默认生成过去100年的所有生日的数据字典

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>

int main(int argc,char* argv[])
{
	FILE*				fpDictionaryFile;
	char				FilePath[256];
	int					year_start;
	int					year_end;
	int					year;
	int					month;
	int					day;
	time_t				rawtime;
	struct tm *			timeinfo;


	printf("Please input savefile's path : ");
	scanf("%255s",FilePath);
	
	if((fpDictionaryFile = fopen(FilePath,"w")) == NULL)
	{
		printf("File create error!");
		return 0;
	}
	
	time ( &rawtime );
	timeinfo = localtime ( &rawtime );

	year_start = timeinfo->tm_year-100;
	year_end = timeinfo->tm_year;

	for(year = year_start; year < year_end; year++)
	{
		for(month = 1; month < 13; month++)
		{
			for(day = 1; day < 32; day++)
			{
				fprintf(fpDictionaryFile,"%04d%02d%02d\n", year, month, day);
				fprintf(fpDictionaryFile,"%02d%02d%04d\n", month, day, year);
			}
		}
	}
	fclose(fpDictionaryFile);
	printf("Successful!\n");
	getch();
}

你可能感兴趣的:(C 语言生成生日字典)