#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);
}
}
x -=y;
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
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.
Use the MOD operator to get the remainder of integer division.
Reference:cprogramming-bd.com/c_page1.aspx# array programming
see the program
x -=y;
1 hour ago my c program said no, but now I know 5 actually is an integer!
The Windows version of Skype is a software program that contains adware.
The minimum GPA required for admission to the master's program is 3.0.
The minimum required GPA for admission to the master's program is 3.0.
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
A computer program contains instructions, to be executed by a computer.
Use %o
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.
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.
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.