answersLogoWhite

0

#include

#include

#include

using std::cin;

using std::cout;

using std::endl;

using std::ifstream;

//function prototypes

int numberOfElements(ifstream& inData);

void readDataFromFile(ifstream& inData, long* dataFile, int arraySize);

int main()

{

const char fileName[] = "data.txt";

ifstream inData;

inData.open(fileName, std::ios::in);

if (inData.fail())

{

cout << endl << "Could not open the file: " << fileName << endl;

inData.close();

exit(1);

}

int numberOfLines = numberOfElements(inData);

cout << "Number of string is: " << numberOfLines << endl;

long* dataFile = new long[numberOfLines];

readDataFromFile(inData, dataFile, numberOfLines);

for (int index = 0; index < numberOfLines; index++)

{

cout << endl << *(dataFile + index) << endl;

}

delete [] dataFile;

system("PAUSE");

return 0;

} //calculate number of elemenets and return its value

int numberOfElements(ifstream& inData)

{

double data = 0.0;

int counter = 0;

while (inData >> data)

{

counter++;

}

inData.clear();

return counter;

}

//read data from file and save it in array dataFile with size arraySize

void readDataFromFile(ifstream& inData, long* dataFile, int arraySize)

{

for (int index = 0; index < arraySize; index++)

{

inData >> *(dataFile + index);

}

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

What is the code of a c program that will read in a positive integer value and determine If the integer is a prime number and If the integer is a Fibonacci number?

see the program


Write a program to subtract integer y from integer x?

x -=y;


Is -5 a integer?

1 hour ago my c program said no, but now I know 5 actually is an integer!


What is a software program that contains Adware?

The Windows version of Skype is a software program that contains adware.


What is the minimum GPA required for admission to the master's program?

The minimum GPA required for admission to the master's program is 3.0.


What is the minimum required GPA for admission to the master's program?

The minimum required GPA for admission to the master's program is 3.0.


How do you find by program a given number is integer or float?

If it contains a decimal point or an exponential part, then it should be handled as a float (or double).You can determine an existing variable's type in C using the type() function


What is a computer program made of?

A computer program contains instructions, to be executed by a computer.


Wrie a program to receive an integer and find its octal equivalant?

Use %o


How would you write a program that read an integer for display each of digit of integer in English?

Use an enum if you are using a c style language. Or a map data structure. Assign each integer an English value and then match it to what the user inputs.


What is the minimum GPA required for admission to a master's program?

The minimum GPA required for admission to a master's program varies depending on the institution and program, but it is typically around 3.0 on a 4.0 scale.


What is the minimum GPA needed for admission to a master's program?

The minimum GPA required for admission to a master's program varies depending on the institution and program, but generally, a GPA of 3.0 or higher is commonly required.