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();
}

The structure st is wrong and you don't need to malloc() anything. Actually you don't need that structure at all unless you intend to add some other members later on.

abc.txt -- is it a text file (you can red it with Notepad) or a binary file (Notepad just shows junk on the screen) ?

The structure st is wrong and you don't need to malloc() anything. Actually you don't need that structure at all unless you intend to add some other members later on.

abc.txt -- is it a text file (you can red it with Notepad) or a binary file (Notepad just shows junk on the screen) ?

.......YES IT DID SOLVED THE PROBLEM........
HEY,CN U HELP ME OUT WITH DATA STRUCUTE IN C NOWWW.PLZ REPLY

commented: This is not a chat room. Try to write in proper English next time. -2
commented: I hate l33t chat-room sp3ak :angry: -2

What help do you want ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.