•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,802 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,455 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 1092 | Replies: 4
![]() |
Hello, this is my first post here. I'm taking c++ as an elective course, and I'm doing great until now. The problem I'm having is taking data from a txt file formatted line by line
#### # ## for product id, store number, and quantity. I'm supposed to read this data and store it in three different arrays for each token. I think I can get it from there, but I don't know where to start, which library to use, confused by existing tutorials I've read, getting frustrated. Plz help. •
•
Join Date: Jun 2005
Location: Tokyo, Japan
Posts: 1,480
Reputation:
Rep Power: 8
Solved Threads: 98
some progress made. i may have just needed the personal note --have been working on this stuff all day, the end of the term is coming on fast and we just took test 1 of 3 yesterday. here she is:
which gives the following errors:
I'm using gnu compiler if this matters.. what am i doing wrong? thx
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool loadArrays(const char fileName[], long idArray[],
int storeArray[], int qtyArray[], int & count, int maxCells);
void printArrays(ostream & where, const long idArray[],
const int storeArray[], const int qtArray[], int count);
bool extractData(const char newFileName[],int requestId, int baseQty,
const long idArray[], const int storeArray[],
const int qtArray[], int count, int & newcount);
const int ORDER_VALUE = 500;
int main() {
/*
fileName - the Windows name of the file created in step 1
newFileName - the Windows file name of the file of extracted records
requestId - the product id number used to extract data
ORDER_VALUE - the quantity value used to extract data, make this
a global constant with a value of 500
idArray - the array of id numbers
storeArray - the array of store numbers
qtyArray - the array of quantities
count - the actual number of cells filled in the arrays
newcount - the number of extracted records written to
*/
char fileName[] = "products.txt";
char newFileName[] = "list.txt";
int requestID;
int idArray[ORDER_VALUE], storeArray[ORDER_VALUE], qtyArray[ORDER_VALUE];
int count = 0, newCount = 0;
if( loadArrays(fileName, idArray, storeArray, qtyArray, count, 20) )
printArrays(cout, idArray, storeArray, qtyArray, count);
return 0;
} // end main
bool loadArrays(const char fileName[],long idArray[],
int storeArray[], int qtyArray[], int & count, int maxCells) {
ifstream in;
in.open(fileName);
if(!in) return false;
for(int i = 0; !in.eof(); i++) {
in >> idArray[i];
in >> storeArray[i];
in >> qtyArray[i];
count = i;
}
in.close();
return true;
}
void printArrays(ostream & where, const long idArray[],
const int storeArray[], const int qtyArray[], int count) {
for(int i = 0; i <= count; i++)
where << idArray[i] << " " << storeArray[i] << " " << qtyArray[i] << endl;
}
bool extractData(const char newFileName[],int requestId, int baseQty,
const long idArray[], const int storeArray[],
const int qtArray[], int count, int & newcount) {
}which gives the following errors:
•
•
•
•
project03.cpp: In function ‘int main()’:
project03.cpp:48: error: invalid conversion from ‘int*’ to ‘long int*’
project03.cpp:48: error: initializing argument 2 of ‘bool loadArrays(const char*, long int*, int*, int*, int&, int)’
project03.cpp:49: error: invalid conversion from ‘int*’ to ‘const long int*’
project03.cpp:49: error: initializing argument 2 of ‘void printArrays(std::ostream&, const long int*, const int*, const int*, int)’
I'm using gnu compiler if this matters.. what am i doing wrong? thx
Last edited by Dave Sinkula : Jul 11th, 2006 at 4:33 pm.
•
•
Join Date: Jun 2005
Location: Tokyo, Japan
Posts: 1,480
Reputation:
Rep Power: 8
Solved Threads: 98
That is because you have declared the second arguments of
Change the declaration of
loadArray and printArray as a long array but you are inputing an int array.Change the declaration of
idArray from int to long, or just use int in the function declarations. I dont think you will want it to use long arrays. The range of int should be enough. バルサミコ酢やっぱいらへんで
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- Doesn't open for file input successfully.... why? (C++)
- file input problems (with windows?) (Java)
- Reading file input into an array (C++)
- Storing file input to an array? (C)
- File input. (C++)
- vc++ mfc-i can't make getline work with a string for file input (C++)
- reading a file into code (Java)
Other Threads in the C++ Forum
- Previous Thread: Stacks using doubly linked lists
- Next Thread: Data Structures???



Linear Mode