텍스트 파일을 사용하여 생활의 게임을위한 C 프로그램을 만들려면 공간.는 어떻게에 요청했다
Display the initial generation using the function printf.
Calculate the next generation using the rules mentioned above and save it in another textfile.
The filenames of the input and output textfiles should be specified as command-line parameters.
나는 지금까지 텍스트 파일을 요구하는 코드가 있습니다. 코드는 그것을 인쇄합니다. 나는 Conway의 Game of Life의 규칙을 적용하는 코드가 부족하다. 나는 어디에 넣어야할지 모른다. 그리고 사용할 코드. :(좀 도와주세요 내가 지금 무엇을
here`s :...
#include <stdio.h>
#include <string.h>
#define MAX_LINE_LEN 80
#define N 25
void display(char [][N+1], size_t);
int main(int argc, char *argv[]) {
FILE *fp;
char in[MAX_LINE_LEN];
char grid[N][N+1] = { { '\0' } };
size_t i = 0;
printf("Enter filename: ");
fgets(in, MAX_LINE_LEN, stdin);
*(strchr(in, '\n')) = '\0';
if ((fp = fopen(in, "r")) != NULL) {
while ((i < N) && (fgets(in, MAX_LINE_LEN, fp) != NULL)) {
*(strchr(in, '\n')) = '\0';
/* should verify only 'x' and space in string before storing */
strncpy(grid[i++], in, N);
}
/* pad each row with spaces, if necessary, for NxN array */
for (i = 0; i < N; i++) {
while (strlen(grid[i]) < N) {
strcat(grid[i], " ");
}
}
/* For all generations ...
compute next generation */
display(grid, N);
/* End for all generations */
} else {
printf("%s not found.\n", in);
getch();
}
getch();
}
void display(char a[][N+1], size_t n) {
size_t i;
for (i = 0; i < n; puts(a[i++]));
}
가능한 [C 언어를 사용하여 게임을 만드는 방법] (http://stackoverflow.com/questions/9589328/how-to-make-a-game-of-life-using-c-language) – AShelly
또한보십시오 http://stackoverflow.com/q/1823/10396 – AShelly