无聊的帖子
char SunshineGirl[5][5] = {
{1},
{1, 1},
{1, 2, 1},
{1, 3, 3, 1},
{1, 4, 6, 4, 1}
};
谁会把符合c语言语法的文本格式的数组解析到内存中去?
[ 本帖最后由 SunshineGirl 于 2015-4-16 12:20 编辑 ]
#include <stdio.h> #define M 5 #define FILENAME "SunshineGirl.dat" int main(void) { FILE *fFile = NULL; unsigned char arrToWrite[M][M] = { {1}, {1, 1}, {1, 2, 1}, {1, 3, 3, 1}, {1, 4, 6, 4, 1} }; unsigned char arrToRead[M][M] = {{0}}; int i = 0; int j = 0; if ((fFile = fopen(FILENAME, "rb+")) == 0) { printf("open %s error.\n", FILENAME); return 1; } fwrite(&arrToWrite, sizeof(arrToWrite), 1, fFile); fseek(fFile, 0, SEEK_SET); fread(&arrToRead, sizeof(arrToRead), 1, fFile); fclose(fFile); for (i = 0; i < M; i++) { for (j = 0; j < M; j++) { printf("%d ", arrToRead[i][j]); } putchar('\n'); } return 0; }