C :: Double Linked Structure Between 2 Threads

Jun 2, 2014

I am on a little project involving TCP socket-programming and multiple threads but need passing structures between two threads.

The first thread receives data with respective ID, temp, etc,.. Each ID is a list-item of a linked list and every ID has again a linked list of all the received data.

The second thread just have to access the list and perform some manipulations on it.

My solution: pass the head pointer of the linked list. Easy enough, right? Somehow, I am stuck receiving error message:" dereferencing pointer to incomplete type."

For the sake of ease and simplicity I just added a stripped down version of the project.

The magic (or not) happens in MainProcess.c: The Data thread should receive the pointer (a think) from the Connection thread.

View 5 Replies


ADVERTISEMENT

C :: Double Linked List

Jan 2, 2014

I'm having a small issue here with my linked list.I built a linked list with strings and it worked perfectly.Now since i'm using strtok() to separate the string.for now here's what i've got:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct dict_word *word;
typedef struct node *Node;
typedef struct double_linked_list *DLL;
}

[code]....

View 1 Replies View Related

C++ :: Double Linked List Implementation

Dec 27, 2013

I'm trying to set up a simple implementation of a double linked list... But I seem to some mistakes.

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define ValueType int
struct vertex {

[Code] ....

I get 'Test: root exists' printed out, but not the loop through my linked list.

View 11 Replies View Related

C++ :: Insert Into Certain Position In Double Linked List?

Jul 26, 2013

I'm having trouble inserting a node in a nth position into a double linked list. My for loop is giving me an exception handler error and I can't link the node after the new node is inserted back to the new node. Here is my code,

void mylist::insertpos(const int &pos, const string &s, const int & c) {
listnode* temp1 = new listnode(s,c);
temp1->s =s;
temp1->next = NULL;

[Code]....

I attached my header file incase you need to see the definitions for my objects.

View 4 Replies View Related

C/C++ :: Implementing Stack Using A Double Linked List

May 12, 2014

So im trying to write a code that will take data in from a user and when that user enters specific character then i want to pop the top of the stack and place that node on a new stack. Then if the user enters a different specific character then i want to place what was just popped off the stack back on to the original stack. Anyways i'm just testing what i have without all the complicated stuff with the specific characters, but i get an error and i'm not not well versed in exception handling. So this is what i have so far. the push seems to work well but the pop seems to be giving me problems.

Stack::Stack(){
top = NULL;
bottom = NULL;
}
//method to push a line of text onto the stack
void Stack::push(string data)

[Code] .....

View 4 Replies View Related

C++ :: Double Linked List - Node Undeclared

Apr 2, 2013

I am developing a double linked list in C ( development environment ) is QT with mingw32 4.7 gcc / g++ compiler , in the header file I have defined struct as follows :

Code:
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <stdlib.h>
#include <sys/stat.h>
#include <signal.h>
#ifndef NULL

[Code] ....

When compiling I am getting the following error : 'NODE' undeclared (first use in this function)

and

each undeclared identifier is reported only once for each function it appears in

I have also attached the screen shot from the QT IDE

look's like the compiler is not able to pick up the definition of NODE structure , same happens in Netbeans IDE , interesting thing is if change the source file from c to cpp the error goes away .

View 3 Replies View Related

C/C++ :: Unable To Delete A Node In Double Linked List

Aug 22, 2014

I am trying this without a head/start pointer which would generally hold the address of first node. I have 3 nodes here from which I am trying to delete last node, but its not happening. I might be wrong in my logic and this is my first linked list program.

#include <stdio.h>
#include <stdlib.h>  
struct dll{
            struct dll *prev;
            int data;
            struct dll *next;

[Code] ....

output::::

add of p1::0x9605008 add of p2::0x9605018 add of p3::0x9605028 add of p1->prev::(nil) add of p1->next::0x9605018 add of p2->prev::0x9605008 add of p2->next::0x9605028 add of p3->prev::0x9605018 add of p3->next::(nil)

no of nodes 3

enter the addresss of node to delete it
0x9605028

after deletion attempted

add of p1::0x9605028 add of p2::0x9605018 add of p3::0x9605028 add of p1->prev::0x9605018 add of p1->next::(nil) add of p2->prev::0x9605008 add of p2->next::0x9605028 add of p3->prev::0x9605018 add of p3->next::(nil)

no of nodes 3

In this example i am trying to delete the node 3 which is p3, by deleting its address 0x9605028. But after deletion the node count is still 3 and addresses are like unexpected!

View 1 Replies View Related

C++ :: Implementing Double Linked Lists As Array Of Pointers

Dec 27, 2012

I am studying/writing/ code for a future Advanced Data Structure class in C++; however I am not suppose to use STL, Templates and etc (the way I just code "kinda" of resembles what I have to use).

My application is suppose to read/analyze all integers contained in a text file of 5-digit integers (10000 - 99999).

For simplicity I am using the following input (or check the attached):

20007 20008 20009
20010 20010
20012 20012
20013
20014 20010
20015
20016 ....

So far, my code is not displaying/printing the lists separated by the first digit of these 5-digits integers. I am expecting it to display/print logically/similar to the following:

Output:

Results for input file numbers.txt:
27 total integers read from file

The 3 unique integers beginning with digit 1 were
18399 17342 19948

The 6 unique integers beginning with digit 3 were
39485 34710 31298 38221 35893 32791

The 4 unique integers beginning with digit 4 were
43928 49238 45678 43210

The 6 unique integers beginning with digit 6 were
64545 62987 66221 61777 66666 65432

The 2 unique integers beginning with digit 8 were
88888 86861

The 1 unique integer beginning with digit 9 was
98765

There were 22 unique 5-digit integers in the file.

The highest unique count in one list was 6 integers.

My code that will follow soon displays/prints only the LAST 5-digits "group" of integers (in this case the 5-digits starting with 3). I am not sure what's wrong with my code; perhaps I am not designing it correctly. May be my calls in it are on the wrong place or I have to write all integers and then traverse it and output it (if that's the case, I am not sure how).

My code follows:

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const int MAX_CELLS = 10;
const int UNIQUE_FIVE_DIGIT = 5;

[Code] .....

View 10 Replies View Related

C :: Why Most Examples Pass Double Pointer When Manipulating Linked Lists

Mar 1, 2014

Why do most C examples pass a double pointer when manipulating linkedlists? Why can not we just pass a single pointer to the struct?I think using an external reference accessor for a linked list would be a more appropriate solution, yes or no?

View 1 Replies View Related

C++ :: Read Coordinates From Text File Into Double Linked List

Mar 25, 2014

I am doing c++ program to read coordinates from text file into double linked list. Everything seems to work perfectly but it stores only 298 items in linked list. Im not sure if my code is wrong or I missed something. On the debugger length of list is over a 1000 but like I said it print outs only 298.

View 2 Replies View Related

C/C++ :: Print Name And Ages Forward Then Reverse Using Double Linked List

Apr 28, 2015

I have to write a c program that will allow the user to enter names with ages. The name will be no longer than 40 characters. The name and age should be stored in a node of a doubly linked list. I cant use global data. I need to use 3 subroutines. the first one needs to enter the data and pass the head and tail pointers to the subroutine. the next subroutine needs to print the names and ages to the screen and file output.txt from first to last. the last subroutine needs to print out names and ages to the screen and file output.txt from the last to first.

Im getting several errors when i try to run this program. The first subroutine to get the data from the user and build the double linked list. but i seem to be having issues.

#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int entry(char [][41], int []); // subroutine used for data entry //
void printit(char [][41], int [], int); // subroutine used for data printing //
void reverseprintit(char [][41], int [], int); // subroutine used for reverse data printing //

[Code] .....

View 11 Replies View Related

C/C++ :: Doubly Linked List Versus Double Ended Queue

Jun 27, 2014

A while ago i was asked to write a program for a class that used a "Double ended queue with a current-position marker."

An example of some of the functions that i created are:

boolean atFirst() // Returns true if first element is current. Pre: !isEmpty().
boolean atLast() // Returns true if last element is current. Pre: !isEmpty().
void makeEmpty() // Sets this List to the empty state. Post: isEmpty().
void moveFirst() // Sets current marker to first element.
void movePrev() // Moves current marker one step toward first element.
void moveNext() // Moves current marker one step toward last element.
void insertBeforeFirst(int data) // Inserts new element before first element.

My question is whether a double ended queue with pointer is the same thing as a "doubly linked list" in this case. The terminology is throwing me of a little. If the two concepts are different, how is a doubly linked list different?

View 2 Replies View Related

C++ :: Creating A Class That Would Implement Concept Of Double Linked List Like A Queue

Jun 15, 2013

Well, basically, what I've been doing was creating a class that would implement the concept of Double Linked List, but that would behave like a queue ( the STL implementation is deque, or Double Ended Queue ).

The problem occured when I have been trying to generalize the class using templates. I mean, why use only integers ? Why not double or char or what not ?

Worked perfectly before including all the template stuff..

// Source.cpp <=> Main.cpp
#include <iostream>
#include "DList.h"
using namespace std;
int main(void) {
DList<int> *list;
list = new DList<int>();

[Code] .....

The errors returned by the compiler:

Error1error C2955: 'Node' : use of class template requires template argument listc:usersjumperdesktopc++ otherdouble linked listdouble linked listdlist.h6
Error2error C2955: 'Node' : use of class template requires template argument listc:usersjumperdesktopc++ otherdouble linked listdouble linked listdlist.h6

View 6 Replies View Related

C++ :: Linked Structure For Binary Tree

Dec 16, 2014

So i am implementing the class LinkedBinaryTree and i am aplying "Depth and Height" and "A linked structure for binary tree".

#include <iostream>
using namespace std;
// InspectableContainer
template <typename Object>
class InspectableContainer {
public:
int size();
bool isEmpty() const;

[Code] .....

View 4 Replies View Related

C++ :: Linked List - Structure Naming Syntax

Feb 21, 2014

I am looking at a linked list example, which uses structs:

typedef struct node {
int val;
struct node * next;
} node_t;

As you can see, we provide an optional name "node" that follows the word struct. And we can use "node" subsequently as a shorthand for the part of the declaration in braces.

But what is that node_t for? What is that doing?

View 4 Replies View Related

C++ :: Creating Tree Like Structure Using Linked List

Apr 25, 2014

How would I go about creating a tree like structure using linked lists, I am thinking of making a rubix cube solver program, what I want to do create nodes that each do one operation like turn left, right, up, down but I dont know how to go about starting this.

View 2 Replies View Related

C++ :: Structure Linked Lists - Searching For Words

Apr 8, 2012

So a user inputs an artist name, and then if the input matches one of the nodes containing the artist names i need to return that. but then also if the input does not match any of the nodes, I need to insert a new one. This is to be written in C. Also my structure that this function goes off of is shown below as well.

Code:

artistNodePtr findOrInsertArtist( artistNodePtr *sPtr, char *artistID ) {
artistNodePtr newNodePtr;
temp = sPtr
if(temp->artistName_p == artistID){

[Code] .....

View 14 Replies View Related

C :: How To Copy A Generic Linked List Node Structure

Aug 24, 2013

I am having problems copying this data structure (memory leaks).

Code:
typedef struct List {
int x;
void *ptr;
struct List *next;
} List;

The problem is allocating memory for void *ptr.

View 2 Replies View Related

C :: Use SIGNALS To Control Threads

Nov 11, 2013

I've to use SIGNALS to control threads. Here's my code without the use of signals as I'm no good at that

Code:

#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
}

[code]....

View 4 Replies View Related

C++ ::  threads To Take Sequential Turns

Jun 30, 2014

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

int turn = 1;
int counter = 0;
int t, n;

[Code] ....

I found this program in a forum and it creates 1 to t threads with each thread pointing to the next and the last thread pointing to the first thread and it allows each thread to sequentially take a turn until all threads have taken n turns. That is when the program ends.

My doubt is if we see in void *tFunc(void *arg) function, first thread locks the mutex and then wait there forever till it's turn comes.Lets say if I spwan 1000 threads and they have take 10 turns each sequentially and what if a 550th thread locks the mutex as soon as the program starts and waiting for its turn which will never happen because still (turn=1) which means it's first thread's turn and first 549 threads have to complete their 1st turn before this 550 threda's turn comes.Doesnt this result in deadlock?

View 2 Replies View Related

C++ :: Encapsulate Two Threads In A Class?

Apr 29, 2014

how to encapsulate two threads in a class?

View 1 Replies View Related

C++ :: Stopping Threads Without Using Local Var?

Aug 31, 2014

Here's my code,

#include <iostream>
#include <unistd.h>
#include <thread>
using namespace std;
void Blink();

[Code] .....

The problem is i don't want to use local vars , is ther anyway do end the loop safely(removing all the vars used in function and etc) without using a local var ?

View 3 Replies View Related

C/C++ :: Suspending And Resuming Threads

Apr 18, 2014

#include <stdio.h>
#include <pthread.h>
int i; // loop control variable
int *id; // array used to pass parameter of id
int nThreads; // #threads

[Code]....

I want to know where I am going wrong. I am strong in java but not in c so that may be my problem.

View 9 Replies View Related

C++ :: Creating And Terminating Threads?

Aug 31, 2014

I had a requirement where i needed to create a thread and if the execution of thread is not completed in 5 minutes i needed to terminate its execution and continue with other part of the code.

I used the below code to create the thread

_beginthread(FuncnCall,0,NULL);

HANDLE hThread = GetCurrentThread();

Then after this code, I used the below code to check for 5 minutes

for (int i=1;i<=0;i++) {
printf("Value of i=%d
",i);
if(threadFinished) {
break;
} else {
Sleep(1000);
}
}

After this if the value of "threadFinished" is false then i am terminating the thread like below

if(threadFinished == false) {
TerminateThread(hThread,0);
CloseHandle(hThread);
}

The Problem here is, after terminating the thread, the program abruptly closes by giving fatal error. Looks like memory leakage is happening after terminating the thread. Is it not the right way to safely exit the thread?

View 2 Replies View Related

C/C++ :: Not Able To Initialize Structure Variable Inside Main Whose Structure Defined GL

Aug 27, 2013

I am trying to run a programme implementing a function with structures in c... which is:

#include<stdio.h>
#include<conio.h>
struct store  {
        char name[20];
        float price;    
        int quantity;

[Code] .....

View 1 Replies View Related

C++ :: OpenMP - Intervals Assigned To Threads?

Feb 6, 2014

Is there a way of knowing which indices a thread is assigned in a parallel openMP scope?

View 6 Replies View Related







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