C :: Delete Each Element In The List Which Is Same - Function Does Not Work Properly
Jan 18, 2014
Code:
struct lista* del(struct lista* p, char* path1) {
char model[MAX2];
int len;
char ch;
printf("Type model.
[Code] ..... t
This function should delete each element in the list which is the same as this one typed by user. There are no errors, but function doesn't work. It deletes something, but not this element which should.
View 5 Replies
ADVERTISEMENT
May 21, 2013
This is my code for submitting students but when i use search function the course member is empty
Code: #include "windows.h"
#include "iostream"
#include <io.h>
#include <sstream>
#include <conio.h>
#include <stdlib.h>
#include <iostream>
#define SIZE 5
using std::cout;
using std::cin;
using namespace std;
int menu();
[code].....
View 11 Replies
View Related
Mar 20, 2013
i am facing some problem with qsort() function it work well if the last element of array is larger then the 2nd last element. But in case if last element of array is smaller then the 2nd last it will sort the whole array and remains the last as it is. For example
Code:
int group_id_local[max_j]={2,1,4,5};// it work fine, output should be {1,2,4,5} but if i have this one
int group_id_local[max_j]={2,1,4,3};
// output should be {1,2,4,3}
/* COMPARE FUNCTION FOR USING QSORT()*/
int cmpfunc (const void* a, const void* b)
{
if (*(int *)a < *(int *)b) return -1;
if (*(int *)a > *(int *)b) return 1;
return 0;
[Code]....
why it will not sort the last element?
View 5 Replies
View Related
Mar 10, 2014
So I have linked list and function which deletes element if next element is bigger, so my code is working but its not working with first element, in the comment I have wrote code which I would code for checking that first element, but when ever I check it is blowing up all program.
#include <iostream>
using namespace std;
struct llist {
int x;
llist *next;
[Code] .....
View 1 Replies
View Related
Dec 9, 2014
I have to manage a Clinic. I need to delete a booking (for example, if John said he's coming on March 22nd at 15:30 but then he say he's not going to come, I have to delete that booking so another person can use it).
idSearched: the id of the person that is not going to come. I have a lot of specialties and each one has a list. So I ask for the speciality to delete the node (the node contains John's booking). If I don't find it, I return (-1). searchSpecByID return a pointer to the list where the speciality is. So head will point to the first node of the list. In nodeToDelete I have the node I want to delete.
The program detects OK when is the first in the list and when not, but it doesn't delete the node.
Code:
typedef struct bookingList{
tSpecialty specialty;
struct nodo* intro;
} tList;
[Code].....
View 7 Replies
View Related
Aug 26, 2014
I am unable to get the string seaching function to work. it always says "Nothing found" I am stumped.
Code:
#include <stdio.h>
#include <string.h>
char tracks[][80] = {
"I left my Heart at Harvard Medical School",
"Newark, Newark, You suck balls",
"Dancing with a dork",
"From Here to maternity",
"The Girl from Iwo Jima",
[Code]....
View 3 Replies
View Related
Dec 16, 2013
this programm should in theory create a labyrinth but it doesnt and i really dont have the skill to pick up where i have been mistaken so gcc runs it but it crashes and it doesnt produce any remarkable results even when it runs....
for example this should you run it with these parameters .
5
5
appear something like this
10111
10101
10101
10001
11111
or like this
10111
10001
11101
10001
11111
but it only crashes....it works with recursion and it makes a array (which is Ptr) a set of 1 and 0 which 0 is the path and 1 is the walls...
Code:
#include <stdio.h>#include <stdlib.h>
#include <time.h>
int **Ptr;
int M, N, P, charge, i,c,j;
void Lab_creator(int vertical, int horizontal,int direction);
[Code] .....
View 2 Replies
View Related
Feb 23, 2013
I am trying to write a function to return the first element of a link list queue. I am not real sure how to implement this. I have include a copy of the struct for my Node & queue.
Code:
typedef struct event_Node {
void *data;
double arri_time;
double serv_time;
double depart_time;
double start_o_serv;
[Code]...
View 4 Replies
View Related
Jan 20, 2014
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
struct node {
int data;
struct node *next;
[Code] ....
The above code is a SLL. I have a problem in my deleteNode function. I can't delete the exact data on the list. How to do this right?
View 1 Replies
View Related
Sep 23, 2014
I am creating a doubly linked list that will store strings, for example:
struct node{
string data;
node* next;
node* prev;
};
node* head; //first element from left to right (global)
node* tail; // last element from left to right (global)
And here is the function:
void deleteNode(int n){
struct node* temp1 = head;
if (n == 1){
head = temp1->next;
free(temp1);
[Code] .....
View 3 Replies
View Related
Aug 12, 2014
My program seems to be working fine, except for when I call on my delete function. I don't receive any errors, but when I call the delete function my program outputs nothing and freezes. As in, my print function (which is called before the delete function) doesn't even work. I've tried removing bits of the function to see if I could pinpoint where exactly the issue is, but I've had no luck.
#include <iostream>
#include <string>
using namespace std;
class List{
private:
struct node{
string _data;
[Code] ....
And the function that is causing me trouble:
void deleteNode(string data){
node* del = NULL;
t = h;
n = h;
while(n != NULL && n->_data != data){
[Code] .....
View 5 Replies
View Related
Jan 9, 2015
how to delete an element(s) from an array; suppose I have an array x[10] = {1,2,3,4,5,6,7,8,9,10}, and I want to delete array{5} so that the values of the array become {1,2,3,4,5,7,8,9,10}; how do I go about this? This is not the same as setting the value of array{5} to null; but completely eliminating it so that it does not get printed alongside the other elements of the screen.
View 3 Replies
View Related
Feb 23, 2013
I have a global list that contains smaller lists of char arrays. I have an issue where when I'm reading back the inner lists the last element of one list seems to point to first element of the next.
So my data looks like the below (values separated by commas with the pairs separated by tabs. The last pair in a line is the same as the first). When I read the first list back instead of seeing "456.678,678.98" as the last element in the list. I see "435.67,234.98" twice: at the end of the first list and start of the other. I have debugged when the list is populated and can see the correct values going in so I can't figure what's happening.
456.678,678.98 123.45,345.56 256.67,789.98 456.678,678.98
435.67,234.98 123.65,342.56 987.78,678.34 435.67,234.98
Code to fill the list:
obstacle_list = op_prg_list_create();
while (fgets(line, sizeof(line), obstaclePositions_traj_file) ) {
token = strtok(line, "
"); //Pull the string apart into tokens using the
input = op_prg_list_create();
[Code] ....
View 3 Replies
View Related
Aug 23, 2012
I have an std list of type double.. and the list is always guaranteed to have just 2 elements. I need to get the value of element 2 minus element 1. What is the least amount of code to accomplish that?
I tried this:
Code:
list<double> dList;
dList.push_back(1.0);
dList.push_back(2.0);
list<double>::iterator iter = dList.begin();
list<double>::iterator iter2 = dList.end();
double result = *iter2 - *iter;
But this code does not work. Why not?
View 6 Replies
View Related
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
Dec 21, 2014
I'm writing a program where the user inputs a number of rows, and that many rows of @ symbols are printed, where the first row has the same number of columns as rows, and each next row decrements the number of columns by 1. It prints out a totally wrong output and whatever I try it won't print the right thing- currently when I input 4 it prints out 5 @ symbols on the first row, and then 3 on all the other rows.
Code:
#include <iostream>
using namespace std;
int main ( ) {
int rows;
cout << "How many rows? ";
cin >> rows;
[Code] .....
View 2 Replies
View Related
May 30, 2013
I'm working on a linked list and was wondering how this looks to everybody else for a deleteList function.
void deleteList(Node* head)
{
Node* iterator = head;
while (iterator != 0)
[code].....
View 6 Replies
View Related
Mar 27, 2013
How can I remove an element in a list when I have only an iterator that points to the object I want to remove. Is there a build in command? remove() takes an object reference as its argument. Is it possible to convert the iterator into a pointer type so it can be deferenced and passed to remove?
This is the code I am working on:
//player.cpp
void Player::CheckCollectableCollisions(std::list<Collectable>& c) {
std::list<Collectable>::iterator i = c.begin();
while(i != c.end()) {
if (Collider::CheckCollision(pNodes_.front().getLocation(), i->getLocation()))
[Code] .....
View 2 Replies
View Related
Nov 26, 2014
Here's my list code:
Color.FromArgb(alfa, 0, 255, 255),
Color.FromArgb(alfa, 0, 255, 0),
Color.FromArgb(alfa, 64, 255, 0),
Color.FromArgb(alfa, 128, 255, 0),
Color.FromArgb(alfa, 192, 255, 0),
Color.FromArgb(alfa, 255, 255, 0),
Color.FromArgb(alfa, 255, 192, 0),
Color.FromArgb(alfa, 255, 128, 0),
Color.FromArgb(alfa, 255, 64, 0),
Color.FromArgb(alfa, 255, 0, 0)
How can I get a specific element value from that list?
For example:
if(true)
{
//get "192" from Color.FromArgb(alfa, 255, 192, 0)
}
I don't see the "Edit" option and I've noticed a slight error in the previous post.There should be, obviously, [code]if(true)
{
//get "192" from Color.FromArgb(alfa, 255, 192, 0)
}
I was missing the closing tag.
View 2 Replies
View Related
Apr 4, 2013
#include <iostream>
using namespace std;
int function(int a,int b) {
return a + b;
} bool function2(int a,int b)
[Code] .....
View 3 Replies
View Related
Jun 6, 2013
This code is from a example in Jumping Into C++ and I understand the example. But it is a practice problem that is to write a program to remove an element from a linked list; the remove function should take just the element to be removed.
Code: #include <iostream>
using namespace std;
struct EnemySpaceShip {
int x_coordinate;
int y_coordinate;
[Code]...
If I got this right I will create a pointer that points to the first SHIP (getNewEnemy) and the other one will not be printed out.
View 7 Replies
View Related
Oct 17, 2014
This is my current code. The code is to remove the element in the list "head" that is "e". The code works if there is only one element in the list but if there are more than 1 element in the list, it doesn't work. The function should return true if there is an element that equals "e" and then it removes it and false if no element equals "e".
bool StringLinkedList::remove(const std::string& e){
StringNode* current = head;
int i = 0;
if (current == NULL)
return false;
[Code] ....
View 1 Replies
View Related
May 2, 2014
I've got this program that I'm working on. Most of the code is from a video tutorial, but I was editing it to be able to search for an element by name. That's working fine, but suddenly the part of the program that prints out all the elements starts in an infinite loop after I input two elements, and search for one.
Here's what I've got:
[code#include <iostream> usingnamespacestd; struct node { int number; string name; node *next; }; bool isEmpty (node *head); char menu (); void insertAsFirstElement (node *&head, node *&last, int number); void insertSorted(node *&head, node *&last, int number); void remove(node *&head, node *&last); void showList (node *current); void showByName (node *current, string name); bool isEmpty (node *head) { if (head == NULL) { return true; } else { returnfalse; } } char menu () { char choice;
[Code] .....
View 8 Replies
View Related
Sep 6, 2014
I'm trying to calculate the total price of books contained in a linked list. I've tried getTotal() function in linked list but error: no match for 'operator+=' in 'total += ptr->Node<Book>::info'| occurred. How can I access the price in the node and then calculate the total price.
Here is part of my code :
Book class
class Book {
protected :
int id;
string title;
double price;
string bookStatus;
[code]....
View 2 Replies
View Related
Nov 11, 2013
I have been trying to implement a way to remove a post from a list of posts implemented with a template doubly linked list. I have thought that the best way to do this might by operator overloading, but I have digressed. I have just thought of using a isEqual that checks equality, but when trying to implement i'm getting weird errors.
This is within my class wall, which is a linked list of wall posts, getPostInfo is within the class WallPost.
bool isEqual(WallPost const & a, WallPost const & b)
{
if(a.getPostInfo() == b.getPostInfo())
return true;
else
return false;
}
I have several instances of the error "void illegal with all types" on line 3. It also is complaining about a not being a arithmetic, unscoped enum, or pointer type. I am assuming that it is because my getPostInfo function is a void.
View 16 Replies
View Related
Sep 22, 2012
I'm working with a cross-platform library which defines a function to obtain function addresses from a shared object (i.e. a DLL on Windows). Here's my modified version of the function which works (albeit only on Windows of course):-
Code:
typedef void (*SuilVoidFunc)(void);
/** dlsym wrapper to return a function pointer */
static inline SuilVoidFunc
suil_dlfunc(void* handle, const char* symbol) {
return (SuilVoidFunc)GetProcAddress((HMODULE)handle, symbol);
}
Now, here's the original (cross-platform) version which is giving me a run time error on Windows:-
Code:
typedef void (*SuilVoidFunc)(void);
#define dlsym GetProcAddress
/** dlsym wrapper to return a function pointer */
static inline SuilVoidFunc
suil_dlfunc(void* handle, const char* symbol) {
typedef SuilVoidFunc (*VoidFuncGetter)(void*, const char*);
VoidFuncGetter dlfunc = (VoidFuncGetter)dlsym;
return dlfunc(handle, symbol);
}
That original version fails at the final return line. The error message says "The value of ESP was not properly saved across a function call".
I'm assuming there's a problem with the declaration of VoidFuncGetter (i.e. it'll assume that the caling convention for GetProcAddress() is cdecl when in fact, it's stdcall). What's the most elegant way to fix this and still keep cross-platform compatibility?
View 1 Replies
View Related