am new to C Code and I have a little task am trying to achieve:
I have a text file with a table of 15*30 which has the following format:
ksjdhfbrshyuekjdhsngfurjsleotj
adslkjhasd;flkjnhafdskjnbdsfnn
sadfkjasdfnasdfnafdjgsadlfkjda
............ and so on
am trying to read this file and store the table in an 15*30 array and print it to the screen. so each character will take one field of the array. I have the code but for some reason its not functionning:
Expand|Select|Wrap|Line Numbers
- #include <stdafx.h>
- int main()
- {
- FILE *cfPtr;
- char arr[15][30];
- int i=0, j=0;
- if ((cfPtr = fopen("puzzle1.txt", "r")) == NULL){
- printf("There was an error\n");
- }
- else{
- while (!feof(cfPtr)){
- for(i=1;i<=15;i++){
- for(j=1;j<=15;j++){
- fscanf(cfPtr, "%c", arr[i][j]);
- }
- }
- printf("the array is %s\n",arr);
- }
- fclose(cfPtr);
- }
- return 0;
- }
regards,
Mohammad