C# :: Adding To A String List

Feb 25, 2014

So I have this code:

temp =count + " x " + name;
if (count > 0) { Stats.Inventory.Add(temp); }

Where Inventory is declared as

public static List<String> Inventory, Sellables;

and temp and count are declared locally as

double count = 0;
string name = string.Empty,temp = string.Empty;

An it throws an error

>Craft.exe!Craft.Stats.InventoryUpdate(string NewInventory) Line 166 + 0x73 bytesC#

My main questions is why? This is my first time using lists

View 14 Replies


ADVERTISEMENT

C :: Linked List / Adding Element To Beginning Of List

Dec 31, 2014

Code:

// Write a function called insertEntry() to insert a new entry into a linked list.

Have the procedure take as arguments a pointer to the list entry to be inserted (of type struct entry as defined in this chapter), and a pointer to an element in the list after which the new entry is to be inserted.

// The function dveloped in exercise 2 only inserts an element after an existing element in the list, thereby prenting you from inserting a new entry at the front of the list.

(Hint: Think about setting up a special structure to point to the beginning of the list.)

#include <stdio.h
struct entry1 {
int value;
struct entry1 *next;
};

[code]...

This is a working version of the exercise, but I don't think I'm doing what's asked. I was able to add an element to the beginning of the list using an if statement, not creating a special structure that points to the beginning of the list. How would I go about creating a special structure that points to the beginning of the list to add a new element at the beginning of the list?

View 8 Replies View Related

C :: Seg Fault When Adding To List

Apr 3, 2013

I am currently working on a program and Originally I was to create a bash program to extra information from youtube and create a table of users, views, titles, duration, etc. (I sent each to a txt file)..Then I was to create a C program to use the extracted information. In this case Users and read in the conents of user.txt and construct a linked list to hold the information. Then print from the Linked list.I managed to do that,

Code:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LINE_LENGTH 100
void build_a_lst(), print_a_line(), print_lst();
void insert_at_end();
}

[code]...

What I have to do now is start reading in The other files and construct a table. And radix sort it by views. But to get to the radix sort part I get stuck on reading in all the files correctly and having the linked list hold them. I keep getting seg faults when I change my code.

View 3 Replies View Related

C++ :: Adding And Deleting From List

Dec 11, 2014

I am writing a program to list the 8 planets, then you select which planet you want. it gives you the mass of the planet, the radius, then you use the mass and radius of the planet to find the surface area (sphere formula) and the density of the planet. Along with those options, you have to add and delete a planet from the list and then sort them alphabetically. All i am having trouble with is the adding and deleting part. The code the adding and deleting from the list would go in cases 9 and 10.

heres my code as of this point.

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
void print(const std::string& item) {

[Code] ....

View 5 Replies View Related

C/C++ :: Adding And Deleting From List

Dec 11, 2014

i am writing a program to list the 8 planets, then you select which planet you want. it gives you the mass of the planet, the radius, then you use the mass and radius of the planet to find the surface area(sphere formula) and the density of the planet. along with those options, you have to add and delete a planet from the list and then sort them alphabetically. All i am having trouble with is the adding and deleting part. the code the adding and deleting from the list would go in cases 9 and 10.

heres my code as of this point.

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
void print(const std::string& item) {

[Code] ....

View 3 Replies View Related

C :: Linked List - Adding Nodes

Jul 23, 2014

I wrote function to add to elements in the list, but when I call printList function it returns me empty list ! I'm new with linked list in C

Output:

Empty list
List is empty add element at the begining
New node with packet num 245
List is not empty add element at the end
New node with packet num 486

Linked list: Empty

Main:

Code:

int main(){
struct node * start ;
start = NULL;
int i;
/*Check if list is empty*/
if(start == NULL){
printf("Empty list

[Code]...

View 2 Replies View Related

C :: Adding To Middle Of Linked List

Feb 17, 2013

I'm trying to make a function that lets me pass an index and a string and will insert the string at that index in the linkedlist..

Code:

typedef struct node {
char* value;
struct node* next;
}

[code].....

View 4 Replies View Related

C++ :: Adding At The Beginning Of Linked List

Aug 18, 2013

I've been struggling with linked list for a few days. I've tried performing a few operations. Here is my code. the add_begin() function doesn't seem to work.

#include<iostream>
using namespace std;
struct node {
int data;
node *next;

[Code] .....

View 8 Replies View Related

C++ :: Linked List Adding Nodes?

Oct 17, 2014

Ok so I am having difficulty adding nodes to my linked list....

how to add a third node while keeping track of the address...Thats where I get lost..I don't know how to keep track of the addresses of the next node..

#include <iostream>
using namespace std;
typedef struct Node{

[Code]......

View 1 Replies View Related

C :: Adding A Second Node To A Doubly Linked List

Mar 6, 2015

I am having trouble adding a second node to a doubly linked list. I define my list as follows:

Code:

typedef struct Node {
char command[256];
int length;
struct Node *prev;
struct Node *next;
} userInput;
}

[code]...

Now, when I iterate back through my list (I want to start at the tail and work my way towards the head), I can only ever get the 1st node to print, then the 2nd node is garbage, which means, to me, that I've linked something wrong.

View 3 Replies View Related

C :: Reading Data From A File And Adding Them To A List

Jun 1, 2014

I've been trying to write my homework assignment (a list of countries, their codes and their capitals) and I've done most of it but I'm stuck at this: I have to open a file, read it and if there are data, add them to the list. So far I've created an element of the structure, queue list, printed the list on the screen and freed the memory. I thought that for reading the file and adding the data I could first open the file (of course) with fopen and after that use a for loop (i=0;i=!EOF;i++) to scan the whole file and fscanf(fp,"%s",result->country),etc in the loop to add the data to the structure of the element and finally insert that element to the queue list. However, when I try to do these operations, I only get to writing the name of the file and the program crashes.

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct List {
char country[20];
char code[5];
char capital[20];
struct List*next;

[Code] .....

View 1 Replies View Related

C++ :: Adding To The End Of A Doubly Linked Circular List?

Dec 2, 2014

Should my if statement be

if (tail== NULL) or if(tail->next == tail) ?

View 4 Replies View Related

C/C++ :: Adding File To The List Of Link Libraries

Jul 28, 2014

I tried to add a .a file to the list of link libraries, but when I build, I'm confronted with the following;

ld.exe||<the path>: Permission denied

I'm an admin on this machine - What?

View 14 Replies View Related

C/C++ :: Access Violation Adding A Pointer To List?

Feb 17, 2014

This code works:

//void Fighter::LoadAnimation(...){
std::list<SCML_SFML::Entity*> entities;
for(std::map<int, SCML::Data::Entity*>::iterator e = data.entities.begin(); e != data.entities.end(); e++) {
SCML_SFML::Entity* entity = new SCML_SFML::Entity(&data, e->first);
entity->setFileSystem(&fs);
entity->setScreen(&window);
entities.push_back(entity);//problem line
}
}

But if i change entities to a member variable, std::list<SCML_SFML::Entity*> Fighter::m_entities, it does not. Instead i get a write access violation when i try to push_back(entity). i need it to be a member variable because i need to use it in other member functions.

View 3 Replies View Related

C/C++ :: Adding Linked List In Sorted Order

Sep 22, 2014

I am currently trying to add to a linked list in sorted order but I have reached an impasse. I can get it to add in sorted order if it belongs in the beginning or second in the list. If i were to type in 9 then 4 i would get 49, but if i type in 5 it changes it to 559. I'm just at a loss and need some sort of direction.

#include "singly_linked_list.h"
#include <iostream>
using namespace std;
void add_node(node*& head_ptr, const int& payload){
if (head_ptr == nullptr) {
node* my_node = new node();
my_node->data = payload;

[Code]...

View 2 Replies View Related

Visual C++ :: Template - Adding Elements To List

Jun 9, 2013

I'm doing a homework aasignment on templates, and i have to build a list. The problem starts when i am trying to add elements to the list. For instance if i chose to add 5 different elements (1,2,3,4,5) the output will be (5,5,5,5,5).

Code:
void add_back(T t){
Node* tmp = new Node;
tmp -> m_data = &t;
if(m_head == NULL) {

[Code] ....

View 4 Replies View Related

C/C++ :: Making New Class Instance And Adding To Linked List

Oct 31, 2013

I have a .cpp file which contains 5 smaller defined classes. In my missile class I have a default constructor and a constructor that I invoke

class Missile{
private:  
bool isHuman;

[Code]...

My issue is when creating and adding the pointer object; it doesn't seem to create a new instance of the class-the Missile objects all share the same xPos value which is always the first xPos when the "fire" command is given. The "Missile *missile = new Missile(xPos, yPos, true);" line does not seem to create a new instance of the object with different variables but instead creates a new object with the same variables. Is it necessary for me to always make a separate .cpp and .h file for any class I want to create multiple instances of or can I keep the smaller classes in the same file and still create a new separate instance of the class?

View 3 Replies View Related

C/C++ :: Adding Two Doubly Linked Lists And Displaying The Resulting List

Oct 9, 2014

can we pass two linked lists as argument in a member function to add two linked lists? and how to access them both in the function??

View 1 Replies View Related

C++ :: Adding And Multiplying Polynomials - Linked List And Operation Overloading

Mar 3, 2013

I am having a bit of difficulty with implementing an object oriented program that uses both linked lists and operator overloading. The program calls for adding and multiplying polynomials together, with each single polynomial being represented as a node of a linked list (which is further a data member of an object of a class I have defined to implement this program). For example:

polynomial A will be: 3x^4 // 1 node of a linked list
polynomial B will be: 5x^2 // 1 node of a linked list
polynomial C will be blank for the time being. // empty list

Now, I need to use operator overloading so that this following line of code can be implemented:

C = A + B;

C should now be: 3x^4 + 5x^2.

The checklist of which parts of my code that work:

constructor works;
copy constructor works;
destructor works;
operator= works;
print function needs work but i can worry about that later;
operator* work on later

Here is my code:

#include <iostream>
using namespace std;
struct termNode {
int exp; // exponent
int coef; // coefficient
termNode * next;

[Code] ....

For the time being I need to add multiple nodes together (with the result being in descending order). So for example:

polyType a(2,3), b(4,5), c(6,7), d;
d = a + b + c;
d.print(); // should print out 7x^6 + 5x^4 + 3x^2, but it will only print out: 3x^2 + 7x^6

View 5 Replies View Related

C++ :: Adding New String Automatically For Each Name

Sep 17, 2012

Im doing a little game, casting dices etc. The problem is that the program will ask for player 1 then if i enter a name and enter it will ask for player two and so going on until i just press enter with a empty field and then continue the game.

The problem is i don't have any clue what code bits to start studying and how i shall lay it up, feels like i need a new string declaration automatically for each name.

View 5 Replies View Related

C++ :: Adding Current Date To The End Of A String

Dec 12, 2014

I need to add the current date to the end of a string but I only need to add the day and not the year or month.

Put the code This is what i have

char date[9];
_strdate(date);
cout << date << endl;

View 1 Replies View Related

C++ :: Adding String But It Return Some Integer Value

Jun 10, 2013

string str = "sfsdfsd"

and i want to add like str[3]+str[4]

but it return some integer value

View 3 Replies View Related

C++ :: Adding New Options To String Class

Oct 8, 2014

I'm giving the replace option to my string:

void replace(string oldstring, string newstring) {
int stroldstringpos=b.find(oldstring);
b.replace(stroldstringpos,newstring.length(),newstring);
}

i have 1 error in these function that i'm confused. imagine the newstring size is more big than the oldstring, how can change the string, but only change the oldstring and add what left?
see these:

String test="hi hello world";
test.replace("hi","hello");

the result must be:

hello hello world

how can i change the replace function for it?

View 3 Replies View Related

C :: Creating Two Dimensional String - Adding Char

Aug 15, 2014

I am making a program that formats a string. I want to create a new 2 dimensional string that will have many other chars and strings in it beside the original string. Then I split the string up on the newlines and return it. Adding different parts to the 2d string e.g. I need to add five _ as chars not string then I need to add different things. First I use sprintf () to add as much as possible. And then I do what to add the rest?

View 13 Replies View Related

C :: Removing A String - Linked List

Feb 19, 2013

I'm trying to go search through my linked list for a passed string and if it matches, remove it...but obviously link everything back together properly. This is what I have so far but when i pass it to my display function, which is properly working, it goes into an endless loop

Code:
void llRemoveString(LinkedList** ll, char* string) {
LinkedList* newNode = (LinkedList*)malloc(sizeof(LinkedList));
newNode->value = string;
LinkedList* n = *ll;

[Code] ....

View 8 Replies View Related

C :: Insert String At Index In Linked List

Feb 17, 2013

I'm trying to make a function that lets me pass an index and a string and will insert the string at that index in the linkedlist... here is so function i have so far:

Code:
typedef struct node {
char* value;
struct node* next;
} LinkedList;

void llAddAtIndex(LinkedList** ll, char* value, int index) {

[Code] .....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved