C :: 2D Array - Input Seems To Lag One Behind When Inserting Data
Jan 27, 2014
For some reason, my input seems to lag one behind when inserting data. Attached, I have code that I wrote along with the example of the lag. What may be wrong with my code that is causing this to lag?
I have the structure defined in the code below and need to insert a new string into the middle of the string array. I know there is a way to insert a new element with a vector. How to do this. I have tried several variations similar to uniqueList.word.insert(400,"disisdabomb"); but with no luck.
const int maxWordCount=1500; struct wordCountList { string word[maxWordCount]; int count[maxWordCount]; }; wordCountList uniqueList;
Below is an extracted portion of an example exercise from the C Programming Language book:
Code: void escape(char * s, char * t) { int i, j; i = j = 0;
while ( t[i] ) { switch( t[i] ) {
[Code] ....
Here's my problem with this. s is a pointer to a char array. That means each index stores 1 byte. A backslash character '' is one byte. In above example, we escape it with a second backslash character: ''. That means we have two bytes there. So why does it allow inserting two bytes into a one byte index?
i am working on creating a priority queue, i seem to have done the algorithm for inserting from the top correctly but the algorithm for inserting from the bottom doesnt seem to work it just overwrites the existing data.
below is my code :
list is an array and listlength is the size of the array declared as a integer
void inserttop(string task) { //int head = 0 ; string temp ; listlength++ ; for (int i = 1; i < listlength; i++) {
I'm having issues trying to input data from a .txt file into my array program. The whole program takes the name, # of goals and assists, adds them together to get points, and then puts in a given + or - rating. The program works except for the data input.
Also, this is an alphabetical "Unsorted" list, but is there a way to order the list based on point value and be able to display that as well as a separate "Ordered" list?
And this is the .txt file. Order is Players Name, Goals, Assists, Plus/Minus rating. The points are added when points = goals + assists (Should be in the main coding above).
I'm trying to pass several integers into the array idAr[10] from an input file using a for loop and then having them output on the console. The output should look like this:
#include <iostream> #include <fstream> using namespace std;
I have a program that stores values in a map>. I use the map as a dictionary so that I can look through my map if a perticular string already exists. If a string does exist, I want to put the position that I found it at (relative to my text file) in my vector. How do I do this? So far I've tried this:
void mapInsert(string aWordNoSpaces, int index){ // check if word exists in map already, but first we need an iterator object map<string,vector<unsigned int>>::iterator it; it = wordMap.find(aWordNoSpaces); if(it == wordMap.end()){ wordMap.insert(pair<string,vector<unsigned int>>(aWordNoSpaces,index));
[Code]...
Also, why are the zeros showing up here (i've attached a screenshot and circled them): [URL]...
I've used qsort to extract the unique student IDs by jumping every four because there's 80 rows of data and twenty students.
I want to make sure it's all working and there's something very strange going on. If you look at my code, when it comes to initialising the structure with the unique student IDs it will happily print them after each one has been initialised inside the for loop (which suggests to me it's obviously done it) but, however, when I want to print them again outside the for loop in another for loop as a "double-check" it goes horribly wrong, presumably they're not in there at all? If you traverse the code to the bottom you'll see my comments.
Now in my for loop, j is going to be incremented 20 times which will correspond to the #define STUDENTS 20. So imagine the array of structure db[j] , the first loop will set i and j both to zero, retrieve the first unique ID and store it in the structure. Then i is incremented by four to acces the next unique ID and then j is incremented by 1 to insert this new ID in the structure.
I have a pointer to a C string that contains multiple lines of text. I need to change a few characters in the string (possibly adding 1-2 extra). At the moment my code looks like this (char **objectData is the pointer):
Code: char temp[350]; char* end = strstr (*objectData, "word_before_data_changes"); strncpy (temp, *objectData, 39); // Copying the first 39 symbols strncat (temp, "6-11", 4); // inputting some data strncat (temp, end, 100); // copying the last symbols.
I don't know how many there would be. Tried sizeof(end), but this cropped off last two lines for some reason. So using 100 at the moment. This sort of works, but I think it also adds some new lines or null-terminating characters in the end or something like that, because data parser cannot parse the modified data after that.
I have a problem with entering math functions in my Bisection method algorithm program. I just don't know how can I make the function that I enter in my GUI app to go from the GUI to the loop and find the root.As far as I googled I only find codes that you need to pre-enter a function in the double/float.
For example:I have a function f(x) = x^3 - cos(x) - x - 3; and I want to enter that function trough the GUI i made in c++..So this is the main code.
#include<iostream> #include<vector> #include<map> using namespace std; class foo { struct type { int i; string s; }y;
[Code] ....
In the sample code
1) why can't we use union if its members have constructors 2) I am not able to insert in Map. 3) also I am not able to use object of struct type y to assign value of its members and later push_back in vector I am getting following error
knils@knils-HP:scott_mayers$ g++ vector_of_struct.cpp vector_of_struct.cpp: In member function ‘void foo::fun() const’:
#include <iostream> #include <fstream> using namespace std; int main() { int r = 0; int c = 0; int num[17][15] = { 0 }; [Code] ...
// Here is my code for displaying the data from the text file into a 2d array and height next to it, but I am not able to diaplay the height from 60 to 76 next to the row of the 2d array, as shown in the table below. This is my program:
Recently the health authorities have listed a new way to calculate the body mass index (BMI) of an individual. Values of 20 – 24 are classified as normal, 25-29 as overweight, and 30-34 as heavy.
The table below is a portion of a typical BMI table.
I want to use a dataset of type set which will have the type pair<char,string> or pair<string,string>. How can i insert values into the set, because i have to initialize the set and will not change the set during the program.
Now I can't put data into the array scoresort[x]. I have tried everything. When the scoresort[x] is not an array I can input data. Although when it is an array it crashes my program. It will not process the line.
This is part of the HighScore section for a game that I am currently making.
I want to insert an element into binary tree using pointer passing through functions. In my program i have used three structure which are follows :-
Code:
struct tree{ int data1; struct tree *leftptr; struct tree *rightptr; }; struct list{ struct tree **data; struct list *node;
[Code]...
Here i think problem is in allocating memory to n2 . why i do this because i want to store the address of address of left and right pointers of tree and extract that address to get the address of left and right pointers. Is my method correct ?
A teacher has asked all her students to line up single file according to their first name. For example, in one class Amy will be in front of the line and Yolanda will be at the end.
Write a program that will read in a file of names. Names should be read until there are no more names to be read. Use LineUp.txt as a test file for your program.
Once all the names have been read in display which student will be at the front of the line and which one would be at the end of the line. You may assume that no two students have the same name.
These are the name in the LineUp.txt file if needed: Cooper Gavin Joseph Sierra Kacie Dylan Kaylee Will