hi guys i have an urgent problem....we have been asked to make a battleship game in C which will have the formation of ships taken by a file txt.....for example 00000000
ppp00000
0000nnnn
00000000
etc...i want to open the file txt and then put every single character 0,p,n etc to an array,,,for example array[0]=p,array[1]=p array[3]=0...
can u tell me how?i found only the down code which though cant change line....and if i put many chars it has error....pliz help emergency,,,
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
system("chcp 1253 > nul");
char buffer[6] = {0}; /* initialized to zeroes */
int i, rc;
FILE *fp = fopen("c:\\1.txt", "rb");
if (fp == NULL) {
perror("Failed to open file \"myfile\"");
return EXIT_FAILURE;
}
for (i = 0; (rc = getc(fp)) != EOF && i < 6; buffer[i++] = rc)
;
fclose(fp);
if (i == 6) {
puts("The bytes read were...");
printf("%c %c %c %c %c %c \n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4],buffer[5]);
} else
fputs("There was an error reading the file.\n", stderr);
system("PAUSE");
}