Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's wrong with this code?
#1
Code:
#include <stdio.h>

struct myStruct
{
  int a;
  int b;
};

int main(void)
{
  FILE* foo;
  struct myStruct bar;

  foo = fopen("foobar.txt", "rb");
  fread(&bar.a, 4, 1, foo);
  fclose(foo);
  printf("%d\n", bar.a);

  return 0;
}

The program generates a runtime exception when executing the fread() command. What's the correct way to do this?
Reply


Messages In This Thread
What's wrong with this code? - by Fiel - 2009-10-14, 11:19 AM
What's wrong with this code? - by Orit - 2009-10-14, 11:34 AM
What's wrong with this code? - by Fiel - 2009-10-14, 11:39 AM
What's wrong with this code? - by Orit - 2009-10-14, 11:40 AM
What's wrong with this code? - by Fiel - 2009-10-14, 11:43 AM
What's wrong with this code? - by Orit - 2009-10-14, 11:47 AM
What's wrong with this code? - by Tempus - 2009-10-14, 01:38 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)