⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file.c

📁 一遗传算法的例子源程序
💻 C
字号:
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "lithos.h"

static char token[256];

static int readChar(FILE *f)
{
	int c = fgetc(f);
	if (feof(f))
	{
		printf("Unexpected end of file\n");
		exit(EXIT_FAILURE);
	}
	return c;
}

static void readComment(FILE *f)
{
	int c;
	do
		c = readChar(f);
	while (c != ']');
}

static void readToken(FILE *f)
{
	int c;
	int i = 0;
	do
	{
		c = readChar(f);
		if (c == '[')
			readComment(f);
	}
	while (isspace(c) || c == '[');
	do
	{
		token[i++] = c;
		c = readChar(f);
	}
	while (isalpha(c) || isdigit(c) || c == '-');
	if (c == '[')
		readComment(f);
	token[i] = 0;
}

char *readString(FILE *f)
{
	readToken(f);
	return token;
}

int readInt(FILE *f)
{
	readToken(f);
	return atoi(token);
}

void writeString(FILE *f, char *s)
{
	fprintf(f, "%s", s);
}

void writeInt(FILE *f, int n)
{
	fprintf(f, "%d", n);
}

void writeCommentedInt(FILE *f, char *comment, int n)
{
	int i;
	fputc('[', f);
	writeString(f, comment);
	fputc(']', f);
	for (i = 22 - strlen(comment); i > 0; i--)
		fputc(' ', f);
	writeInt(f, n);
	fputc('\n', f);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -