Chào mọi người, hiện e viết 1 chương trình nhận file dictionary.txt vào mảng 2 chiều như hình ạ.
Ý tưởng của e là khi gặp ký tự xuống dòng thì hàng của mảng tăng 1, nhưng tới đoạn này thì e không biết phải code như thế nào. Mong mọi người chỉ giúp e với ạ.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
FILE * fp;
fp = fopen("dictionary.txt","r");
char points[1000][20];
int i=0,j;
for(j=0; j<20; j++) {
if(points[i][j] == '\n'){
i++;
fscanf(fp,"%c",&points[i][j]);
}
else{
fscanf(fp,"%c",&points[i][j]);
}
}
printf("%c\n",points[0][0]);
printf("%c\n",points[0][1]);
printf("%c\n",points[0][2]);
printf("%c\n",points[0][3]);
printf("%c\n",points[0][4]);
printf("%c\n",points[1][0]);
return 0;
}