it prints the integer string b.var CORRECTLY.BUT not it's individual integer constants.....WHY?
(ABCD.TXT is a bin text file containing data 10110000)
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
struct st
{
int var[8];
};
struct str2
{
char a1;
float a2;
int a3;
int a4;
char a5;
char a6;
int a7;
char a8;
};
void main()
{
FILE *fp;
int i=0;
struct st b;
fp=fopen("abcd.txt","r"); //opening the data file
clrscr();
if(ferror(fp)!=0) //If error don't proceed
{
printf("An error has occured:\n");
}
else
{
if(!feof(fp)) //first line of file gives the total
{
b.var[0]=(int *) malloc(8*sizeof(int));
if(fread(b.var,sizeof(struct st),1,fp))
{
printf("var=%s",b.var);
}
}
}
// printf("\nstrlen=%d",strlen(b.var));
for(i=0;i<8;i++)
printf("\nvar[%d]=%c",i,b.var[i]);
getch();
}