| | |
file input don't know where to start
![]() |
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. 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
C++ Syntax (Toggle Plain Text)
#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)’
Last edited by Dave Sinkula; Jul 11th, 2006 at 5:33 pm.
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. バルサミコ酢やっぱいらへんで
![]() |
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???
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph guess gui homeworkhelp homeworkhelper iamthwee ifpug ifstream incrementoperators infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets






