Thread: Arrays and pointers

  1. #1
    Registered User
    Join Date
    Mar 2008

    Arrays and pointers

    If I am reading an array from a pointer, how can I get the first element of array: Right now the following code gets me reading an array of 500 intergers 100 at a time. What if I want to make the first element of my array the sizeof(int). I guess thats a better way to word that question?
    File *fptr
    int data[500]
    fptr = (fopen("xfile.dat", "rb");
    for (i=0, i<500, i +=100)
     fread(&data[i], sizeof(int),100),fptr)
    Right now I am declaring the array size of 500 but if I want to put in my array first element can I declare &data[0] and make it equal to size of int or do I have to take i when its at 0 and use it for my sizeof int.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Are you saying that the first number on your list is the number of numbers to go in the array? Or what?

    sizeof(int) is not something about your program, it's something about your machine (how much space does an int take on this particular piece of silicon).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  2. Pointers and multi dimensional arrays
    By andrea72 in forum C++ Programming
    Replies: 5
    Last Post: 01-23-2007, 04:49 PM
  3. Passing pointers to arrays of char arrays
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 03-31-2006, 05:31 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Help understanding arrays and pointers
    By James00 in forum C Programming
    Replies: 2
    Last Post: 05-27-2003, 01:41 AM