#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <stdlib.h>
typedef struct arr_col_1{
int x;
};
typedef struct arr_col_2{
int x, y;
};
typedef struct array{
int x1, y1;
};
void col_1(FILE *file, int row);
void col_2(FILE *file, int row);
int main(){
FILE* file;
int row = 0, col = 1, i;
char fname[40], chr;
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
do{
printf("\nEnter the file which you want to vizualize = ");
scanf("%s", &fname);
file = fopen(fname, "r");
if(file == NULL){
printf("\nPlease Enter correct file name ");
}
}while(file == NULL);
chr = getc(file);
while(chr != EOF){
if(chr == '\n'){
row++;
}
if((row == 0)&&(chr == ',')){
col++;
}
chr = getc(file);
}
printf("%d row %d col", row, col);
if(col == 1){
col_1(file, row);
}
if(col == 2){
col_2(file, row);
}
getch();
return 0;
}
void col_1(FILE *file, int row){
struct arr_col_1 *arr1;
int i;
arr1 = (struct arr_col_1*)malloc(row * sizeof(struct arr_col_1));
for(i = 0; i < row; i++){
fscanf(file, "%d", &arr1[i].x);
printf("%d\n", arr1[i].x);
}
getch();
}
void col_2(FILE *file, int row){
struct arr_col_2 *arr2;
int i;
arr2 = (struct arr_col_2*)malloc(row * sizeof(struct arr_col_2));
for(i = 0; i < row; i++){
fscanf(file, "%d %d", &arr2[i].x, &arr2[i].y);
printf("%d %d\n", arr2[i].x, arr2[i].y);
}
getch();
}
the above code able to tell no of rows and col but it not show the data it is not able to read the data. please help me out in the above code i send file to the function but it look like i am not able to read the data. i dont know where the problem occurs please help. somewhere i think the problem lies between file pointer but code is run with no error