Hi,

I'm quite bad in c++ and i have this weird (for me), problem that i can't work around.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
.....
int main(){
...
                int *array1=NULL;
		int *buffer=NULL;
		size=....;//a certain size comes from function
		array1= new int[size];// it looks like both array1 and buffer have only 1 element in them. 
		buffer= new int[size];//
...
                file_read(array1,false); //The crazy thing is, when i give static size to the arrays, i can see the array elements but when i send them through this function, the arrays appear on the other side as having 1 element.

This is the part of function where something is wrong.

int file_read(int a[], bool first)
....
		while(!myfile.eof())
   		{
  	 		myfile>> a[i];//the first and only element gets a value, other than that, i keeps increasing, the eof is never reached.
      			i++;
		}
...

The loop in the read function is incorrect. Using eof() like that will cause the last line to be read twice. Here is the standard way to code that loop

while( myfile >> a[i] )
   ++i;

>>The crazy thing is, when i give static size to the arrays, i can see the array elements but when i send them through this function,

Might be your debugger. vc++ 2008 express debugger does the same thing. But don't worry, its really ok.

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.