title: How to iterate through memory block (created with malloc) in C?
body: <p>My objective is to read an unknown amount of integers from a text file, store them into a block of memory, sort them, and output to a new file. I have a program that can read integers from a file and output them, and now I'm trying to implement the sorting part. I'm coming into this class with an arts background, and my professor's instructions on how to use it are unclear to me.</p>
  
  <p>Instructions: Use malloc() to assign a memory block to an integer pointer. Then each time a new integer is read from the input file and the current memory block is not enough to hold it, use realloc() to assign more space to the memory block so as to hold more integers. You may use *(ptr+x) (an equivalent way is to use ptr[x]) to access the (x+1)th integer in the memory block pointed by the integer pointer ptr. You may then apply any sorting algorithm (e.g., selection sort or bubble sort) you've learned in your previous courses to sort these integers.</p>
  
  <p>What I'm not understanding is how to iterate through an allocated memory block in order to sort it. What is this x my professor mentions? If you could clarify how to use this? I don't want to post my code to avoid cheating. Thanks!  </p>