CMissiveOMat::CMissiveOMat() : CGameObject(), _mode(1), _totalMessages(0), _messageNum(0), _personIndex(-1) { // Load data for the messages, their from and to names loadArray(_welcomeMessages, "TEXT/MISSIVEOMAT/WELCOME", 3); loadArray(_messages, "TEXT/MISSIVEOMAT/MESSAGES", 58); loadArray(_from, "TEXT/MISSIVEOMAT/FROM", 58); loadArray(_to, "TEXT/MISSIVEOMAT/TO", 58); }
void main() { const int PS = 3; int ls, pid[PS], quantity[PS]; double price[PS]; string fileName, productName[PS]; ifstream readFile; ofstream writeFile; //----------------------Definition Complete----------------------// printTitle(); cout << "\nWhat file contains your inventory data? "; fileName = getAcceptableName (fileName); loadFileToRead (fileName, readFile); //----------------------Load File Complete----------------------// cout << "\nInput file " << fileName << " successfully opened.\n"; ls = loadArray(readFile, productName, pid, quantity, price, PS); readFile.close(); cout << "I got " << ls << " items.\n\n\n"; printSummary(productName, pid, quantity, price, ls); printStats(productName, quantity, price, ls); cout << "\n\n\nDo you want this info to be saved in a file? "; if ( getYOrN() == 'Y' ) { cout << "\nWhere do you want this report to go to? "; fileName = getAcceptableName(fileName, " OUT.TXT"); loadFileToWrite(fileName, writeFile); printSummary(productName, pid, quantity, price, ls, writeFile); printStats(productName, quantity, price, ls, writeFile); writeFile.close(); cout << "\nYour report can be found in " << fileName << endl; } cout << "\n\nHit ENTER to end the program..."; cin.get(); }
int main() { srand(time(NULL)); int num,array1[SIZE],array2[SIZE]; printf("Enter the size of the input: \n"); scanf("%d",&num); while (checkError(num)==0){ printf("Invaild input enter the size of the input again: \n"); scanf("%d",&num); } loadArray(num,array1); printf("\nInput array 1\n"); printArray(num,array1); loadArray(num,array2); printf("\ninput array 2\n"); printArray(num,array2); printf("\n"); return 0; }
int main(int argc, char* argv[]) { char **wordArray; /* declare the dynamic array of strings */ /* the array is NOT allocated yet */ int capacity = INITIAL_ARRAY_MAX; int wordCount = 0; int i; if (argc != 3) /* if execution command does not have the .exe, an inputFile and an outputFile specified */ { fprintf(stderr,"Usage: %s inputfile outputfile\n", argv[0]); return 1; } if (loadArray(argv[1], &wordArray, &wordCount, &capacity) != 0) /* i.e. if loadArray does not reach the end of the function ("return 0"). * loadArray is called here; it takes in the 2nd argument from the terminal command (the text file of words) and references to wordArray, wordCount, and capacity so we can pass-by-reference. The function parameters, thus, are a string, a triple char pointer, and two int pointers. */ { fprintf(stderr," loadArray failed! Program terminating...\n"); return 1; /* don't need to call exit - we're in main! */ } printf("\nFinished loading %d words.", wordCount); printf("\nArray Capacity is %d\n", capacity); menu(&wordArray, &wordCount, &capacity); if (writeToFile(argv[2], &wordArray, &wordCount) != 0) { printf("Error writing to file\n"); } else { printf("Dictionary written to file '%s'\n", argv[2]); } for (i = 0; i < wordCount; i++) { if (wordArray[i] != NULL) { free(wordArray[i]); } } free(wordArray); return 0; }
int main(int argc, char* argv[]) { char **wordArray; /* declare the dynamic array of strings */ /* the array is NOT allocated yet */ int capacity = INITIAL_ARRAY_MAX; int wordCount = 0; if (argc != 3) { fprintf(stderr,"Usage: %s inputfile outputfile\n", argv[0]); return 1; } if (loadArray(argv[1], &wordArray, &wordCount, &capacity) != 0) { fprintf(stderr," loadArray failed! Program terminating...\n"); return 1; /* don't need to call exit - we're in main! */ } printf("\n Finished loading %d words.\n", wordCount); /* HERE IS WHAT OUR ARRAY LOOKS LIKE NOW wordArray is pointing to a 50-element block of memory wordArray[0] is a char * -> "horse\0" [1] is a char * -> "cat\0" [2] is a char * -> "rat\0" [3] is a char * -> "oryx\0" ... char * -> "bat\0" ... char * -> "alligator\0" ... char * -> "crocodile\0" ... char * -> "pig\0" ... char * -> "monkey\0" [9] is a char * -> "aardvark\0" [10] is a char * -> ???? ... ... ... [49] is a char * -> ???? REMEMBER the 50 char * pointers are stored consecutively in 1 block of memory (which is why wordArray[5], for example, is well-defined, but the strings are distributed "randomly" throughout the heap. */ printArray(wordArray, wordCount);/* comment this out if using a big file!*/ return 0; }
QMap<QString, QVariant> MainWindow::loadDictionary(QDomNode n) { QString itemName = "", itemTag = "", itemContents = ""; QMap<QString, QVariant> returnMap; // Get first element of dictionary n = n.firstChild(); while(!n.isNull()) { // Try to convert the node to an element. QDomElement e = n.toElement(); // The node really is an element. if(!e.isNull()) { itemName = qPrintable(e.text()); itemTag = qPrintable(e.tagName()); Q_ASSERT_X(itemTag == "key", "MainWindow::loadLevelPlist", "Tag should be a key, but isn't!"); n = n.nextSibling(); e = n.toElement(); itemContents = qPrintable(e.text()); itemTag = qPrintable(e.tagName()); // Simple case (either string or number) if(itemTag != "array" && itemTag != "dict") { returnMap.insert(itemName, itemContents); } // Do we have an array? else if(itemTag == "array") { returnMap.insert(itemName, loadArray(n)); } // Else, we have a dictionary. Let the recursion begin. else { returnMap.insert(itemName, loadDictionary(n)); } n = n.nextSibling(); } } return returnMap; }
int main(int argc,char** argv) { //Error checking for the number of argument// if (argc !=3) { printf("Insufficent arguments"); return -1; } //Error checking for existance of input// int size=loadArray(argv[1]); if(size==0) { printf("Unable to open the input file"); return -1; } //Declaration of variables// int id, ngrade,search; //Display output// printf("Student Record\n"); printArray(size); //Search ID and rewritng new grade// printf("\nEnter the ID of the student to search:"); scanf("%d",&id); printf("Enter a grade of the student:"); scanf("%d",&ngrade); // Checking for the existance of the id// if((search=searchArray(size,id,ngrade))==0) { printf("Student with id %d is not present in the class\n"); } //Write a new file with the new revision// else { int x=writeContent(argv[2],size); //Print new output// printf("\nUpdated student record\n"); printArray(size); } sortArray(size); //Bonus Part Sorting array// printf("\nBonus part\nPrinting sorted student record\n"); printArray(size); return 0; }
struct Hjava_lang_Class* java_lang_VMClass_loadArrayClass(struct Hjava_lang_String* str, struct Hjava_lang_ClassLoader* loader) { errorInfo einfo; Hjava_lang_Class* clazz; Utf8Const *utf8buf; const char *buf; int jlen; jchar *js; /* * NB: internally, we store class names as path names (with slashes * instead of dots. However, we must also prevent calls to * "java/lang/Object" or "[[Ljava/lang/Object;" from succeeding. * Since class names cannot have slashes, we reject all attempts * to look up names that do. Awkward. Inefficient. */ js = STRING_DATA(str); jlen = STRING_SIZE(str); while (--jlen > 0) { if (*js++ == '/') { postExceptionMessage(&einfo, JAVA_LANG(ClassNotFoundException), "Cannot have slashes - use dots instead."); throwError(&einfo); } } /* Convert string to utf8, converting '.' to '/' */ utf8buf = checkPtr(stringJava2Utf8ConstReplace(str, '.', '/')); buf = utf8buf->data; clazz = loadArray(utf8buf, loader, &einfo); /* if an error occurred, throw an exception */ if (clazz == 0) { utf8ConstRelease(utf8buf); throwError(&einfo); } utf8ConstRelease(utf8buf); return clazz; }
int main() { inventory invList[MAX_ARR_SIZE]; int count = 0; // holds the number of cells found in original file int newcount = 0; // hold the number of extracted records written to new file int requestId; char fileName[MAX_FILENAME_LEN]; char newFile[MAX_FILENAME_LEN]; cout << "Enter the name of the file to be read: "; cin >> fileName; // inventory.txt // change last parameter to 10 to test when no room for all data if (loadArray(fileName, invList, count, MAX_ARR_SIZE)) { cout << "All data loaded." << endl; } else { cout << "Insufficent storage. Unable to load all data." << endl; } cout << count << " record(s) found" << endl << endl; printArray(cout, invList, count); cout << endl; cout << "Enter new file name: "; cin >> newFile; cout << "Enter product ID to search for: "; cin >> requestId; // product id number extractData(newFile, requestId, ORDER_VALUE, invList, count, newcount); cout << newcount << " record(s) written to file." << endl << endl; return 0; }
QList<QVariant> MainWindow::loadArray(QDomNode n) { QString itemName = "", itemTag = ""; QList< QVariant > returnArray; // Get first item of array QDomNode m = n.firstChild(); while(!m.isNull()) { // Try to convert the node to an element. QDomElement e = m.toElement(); // The node really is an element. if(!e.isNull()) { itemName = qPrintable(e.text()); itemTag = qPrintable(e.tagName()); if(itemTag == "array") { returnArray.append(loadArray(m)); } else if(itemTag == "dict") { returnArray.append(loadDictionary(m)); } else { returnArray.append(itemName); } } m = m.nextSibling(); } return returnArray; }
DArray(std::string const & fn) : D(loadArray(fn)) { }
DArray(stream_type & stream) : D(loadArray(stream)) { }
static ::libmaus2::autoarray::AutoArray<uint64_t> loadArray(std::string const & filename) { ::libmaus2::aio::InputStreamInstance CIS(filename); return loadArray(CIS); }
/* * Convert string name to class object. */ struct Hjava_lang_Class* java_lang_VMClass_forName0(struct Hjava_lang_String* str, struct Hjava_lang_ClassLoader* loader) { errorInfo einfo; Hjava_lang_Class* clazz; Utf8Const *utf8buf; const char *buf; int jlen; jchar *js; /* * NB: internally, we store class names as path names (with slashes * instead of dots. However, we must also prevent calls to * "java/lang/Object" or "[[Ljava/lang/Object;" from succeeding. * Since class names cannot have slashes, we reject all attempts * to look up names that do. Awkward. Inefficient. */ js = STRING_DATA(str); jlen = STRING_SIZE(str); while (--jlen > 0) { if (*js++ == '/') { postExceptionMessage(&einfo, JAVA_LANG(ClassNotFoundException), "Cannot have slashes - use dots instead."); throwError(&einfo); } } /* * Note the following oddity: * * It is apparently perfectly legal to call forName for array types, * such as "[Ljava.lang.String;" or "[B". * However, it is wrong to call Class.forName("Ljava.lang.String;") * * This situation is similar to the constant pool resolution. We * therefore do the same thing as in getClass in kaffevm/lookup.c, * that is, use either loadArray or loadClass depending on the name. * * This is somewhat described in Section 5.1.3 of the VM * Specification, titled "Array Classes". This section seems to * imply that we must avoid asking a class loader to resolve such * array names (those starting with an [), and this is what calling * loadArray does. */ /* Convert string to utf8, converting '.' to '/' */ utf8buf = checkPtr(stringJava2Utf8ConstReplace(str, '.', '/')); buf = utf8buf->data; if (buf[0] == '[') { clazz = loadArray(utf8buf, loader, &einfo); } else { clazz = loadClass(utf8buf, loader, &einfo); } /* if an error occurred, throw an exception */ if (clazz == 0) { utf8ConstRelease(utf8buf); throwError(&einfo); } utf8ConstRelease(utf8buf); /* * loadClass returns the class in state CSTATE_LINKED. * * Processing to CSTATE_COMPLETE will initialize the class, resolve * its constants and run its static initializers. * * The option to load a class via forName without initializing it * was introduced in 1.2, presumably for the convenience of * programs such as stub compilers. */ if (processClass(clazz, CSTATE_COMPLETE, &einfo) == false) { throwError(&einfo); } return (clazz); }
//call function main and gather inputs from the command line int main (int argc, char* argv[]){ //declare the variables to be used in this program int size, size2; int highest; int lowest; float avg; int findID; int id; int write; if (argc != 4)//check to make sure there are the appropriate number of parameters { printf("\nInsufficient arguments\n"); return 0; } size = loadArray(argv[1]);//call function to load data from input file ints struct array if (size == 0){//if the input file cannout be opened quit program return 0; } highest = findHighestgrade(size);//call a function to find the highest grade in the class lowest = findLowestgrade(size);//call a function to find the lowest grade in the class avg = averageClassgrade(size);//call a funciton to calculate the average grade of the class printf("\n\nStudent record"); printArray(size);//display the array of data gathered from the input file //display the results of the previous functions printf("\nThe student with the highest grade is %s with the grade %d", students[highest].name, students[highest].grade); printf("\nThe student with the lowest grade is %s with the grade %d\n", students[lowest].name, students[lowest].grade); printf("\nThe average grade for the class %.2f\n", avg); printf("\nEnter the ID of the student to search: "); scanf("%d", &id);//prompt user to enter an id number to search for findID = searchArray(size, id);//call function to find what student the id entered by the user pionts to if (findID == -1){ printf("Student with the ID %d is not present in the class\n", id);//check to see if correct student number entered } else{ printf("Student with the id %d is %s\n", students[findID].id, students[findID].name);//display the student searched for by the user } size2 = updateArray(argv[2], size); printf("\nUpdated student record"); printArray(size + size2); sortArray(size + size2); printf("\nPrinting sorted student record"); printArray(size + size2); write = writeContent(argv[3], (size + size2), highest, lowest, avg);//call the function to print data in the output file if (write == 0) { printf("\nUnable to open the output file\n"); } return 0; }//end function main