C :: Modifying Linked List - Passing Pointer As Argument

Feb 27, 2015

I am having trouble modifying a linked list. I am writing a function to delete the last node from the linked list, but it gave me incompatible types error.Here is my struct:

Code:
typedef struct PCB{
int id;
struct PCB *next;
struct PCB *prev;
}PCB_rec, *PCB_p;

Here is my function to delete the last node (given the pointer is pointing at the last node of the list):

Code:
void del_last_node(PCB_p *process_list){
PCB_p temp = process_list;
if (temp->prev != NULL){
temp = temp->prev;

[Code] ....

And here is how I called the function:

Code: del_last_node(&process_list);

It gives me the following errors:
initialization from incompatible pointer type at line:
PCB_p temp = process_list
assignment from incompatible pointer type at line:
process_list = temp

View 14 Replies


ADVERTISEMENT

C++ :: Linked List Node Passed As Parameter / Argument Pointer To Pointer Notation

Jan 17, 2014

I was having problems changing the value of my head node I passed it as an argument as head which would be the address. The parameter was defined as struct node *head. like this

bool deleteNode(struct node *head, struct node *delptr)

I tried manipultaing pointer values to change head node value but it did not work. I saw some code online which used pointer to pointers(in code below) to change head node value it worked I dont fully understand why. Would like better understanding of why.

Would also like to know why the argument call needed &head instead of just head.

remove = deleteNode(&head,found); opposed to remove = deleteNode(head,found);

#include "stdafx.h"
#include<iostream>
struct node{

[Code].....

View 1 Replies View Related

C :: Passing Argument 1 Makes Pointer From Integer Without A Cast

Mar 6, 2015

Code:
#include<stdio.h>
print_int_ptr(int *a){

printf(" a %i
" ,a);
printf(" &a %i
" ,&a);

[Code] .....

I get that warning : passing arg 1 of `print_int_ptr' makes pointer from integer without a cast|

View 3 Replies View Related

C :: Passing Argument 1 Makes Integer From Pointer Without A Cast

Mar 26, 2014

I am having some errors with pointers and passing arguments.

Code:

#include <stdlib.h>
#include <stdio.h>
#define MAX_FILE_LENGTH 20
typedef struct node_{
int value;
struct node_* next;

[Code]....

View 3 Replies View Related

C++ :: Passing A Function Pointer As Template Argument To A Class

Aug 15, 2012

I have in the past written code for templated functions where one function argument can be either a function pointer or a Functor. Works pretty straightforward.

Now I am in a situation where I am actually trying to pass a function pointer as template argument to a class. Unfortunately this does not work, I can pass the Functor class but not the function pointer. Below code illustrates the issue:

Code:
#include <string>
#include <iostream>
#include <sstream>
#include <cstdlib>
// For demonstration
const char * external_library_call() {
return "FFFF";

[Code] .....

The idea is to have the definition of the Record class simple and readable and have a maintainable way to add auto-conversion functions to the class. So the lines I commented out are the desirable way how I want my code to look. Unfortunately I could not come up with any way that was close to readable for solving this.

View 3 Replies View Related

C :: Passing Argument Of Incompatible Pointer Type - Warning In Function Call In Main

Jun 4, 2013

Code:
#include <stdio.h>
#include <stdlib.h>
int size_b_row1;
int size_b_col1;

[Code].....

View 2 Replies View Related

C/C++ :: Push Linked List Pointer

Jan 27, 2015

I've been playing around with making a linked list in C and am having trouble adding to the beginning of the list. For the add_beg() function: the statement "head = newNode" only works locally. This leads me to believe this is a pointer problem. However, the add_end() function works correctly. Ideally, I would like to print "0 1 2 3 4" after using the add_end(root, 0). Currently, print only gives me "1 2 3 4".

#include <stdio.h>
#include <stdlib.h>
//Create a node struct
typedef struct node {
//data
int val;

[Code] .....

View 11 Replies View Related

C++ :: Pointer To Last Node Of A Doubly Linked List

Nov 30, 2014

Why is it sufficient to only have a pointer to the last node of a doubly linked list?

View 1 Replies View Related

C/C++ :: Pointer To Last Node Of A Circular Linked List

Nov 30, 2014

Why is it sufficient to only have a pointer to the last node of the list?

View 3 Replies View Related

C/C++ :: Freeing Linked List Node With Pointer?

Mar 30, 2015

I'm having a bit of an issue here. I have a linked list where each node contains a pointer to a string (which has been malloc'd when the node was created and inserted) and a pointer to the next node in the linked list.

I'm creating a function which will free the node (or effectively delete it). However, I'm receiving a free(): invalid pointer error.

My function:

void removeNode(node *(*nodeToRemove))
{
free((*nodeToRemove)->data);
(*nodeToRemove)->next = NULL;
free(*nodeToRemove);
}

Is this how I should go about freeing this node?

View 5 Replies View Related

C++ :: Infinite Loop For Pointer Variable In Linked List

Jan 14, 2014

I am getting and infinite loop for loop pointer variable current which points to head and is incremented by current->next in while loop. I use the pointer variable the same way in my display routine and it works. Here is listing of code.

#include "stdafx.h"
#include<iostream>
struct node{
int data;
node *next;

[Code] .....

View 1 Replies View Related

C# :: Modifying User Controls While Modifying Main Form?

Jul 10, 2014

I am trying to modify a user control while modifying the main form. For example i have my main form open in one visual c# window and my user controls in another. However it seems that in order for my code changes in my user control to have any effect on the main form i need to close all my c# windows and then re-open them and even then that sometimes doesn't work am i doing anything wrong or is this supposed to happen??

Also yes i am saving and clicking build solution on my user controls.

View 14 Replies View Related

C++ :: Maintaining Additional Pointer To First Node In Doubly Linked List

Nov 30, 2014

Why would it be cumbersome to maintain an additional pointer to the first node in a doubly linked list?

View 1 Replies View Related

C++ :: Linked List Set Function - Forbids Comparison Between Pointer And Integer

May 5, 2014

I'm trying to write a function called 'set' that sets the value of the i'th cell to val on my linkedList, and then returns the previous contents. I am stuck on it due to compiling errors:

This is my Node struct:

#ifndef NODE_H
#define NODE_H
#include <iostream>
template <typename T>
struct Node {
friend std::ostream &operator <<(std::ostream &os, const Node<T> &node) {

[Code] ....

The following is my set function:

template <typename T>
T set(Node<T> *head, int i, const T &val) {
for(int n = 0; n < i; n++)
if(head == val) {
val = i;
} return val;
} #endif

When I try to call it in the main() I get these errors:

node_utils.h: In function ‘T set(Node<T>*, int, const T&) [with T = int]’:
node_demo.cpp:26:38: instantiated from here
node_utils.h:161:2: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
node_utils.h:162:3: error: assignment of read-only reference ‘val’

So, I understand that I can't compare head & val on my if-statement -- But what do I do?

View 7 Replies View Related

C++ :: Generic Linked List Compilation Errors / Incompatible Pointer Type

May 19, 2014

I am trying to write a generic linked list in c, but for some reason i keep getting errors saying "incompatible pointer type. This is the code and erros:

#ifndef SLIST_H
#define SLIST_H
#include <stdlib.h>
typedef struct {
void *data;
slist_elem *next;

[code]....

View 2 Replies View Related

C++ :: Passing Argument Into Function

May 21, 2013

How to pass an int that I got from user input into a function to use it. I am trying to print out the words to a string of numbers.

I got the input from user.
I got an absolute value of the input.
I then separate the string into individual digits and name them.
I can print these out.
Then I started my if statement by checking if the original input was zero, and if it is, printing zero and exiting.
Then I an trying to pass the digits into a switch function and this is where I go off the rails.

Code:
#include <iostream>
#include <string>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

[Code] .....

View 7 Replies View Related

C/C++ :: Passing Function As Argument

Mar 11, 2015

I have two questions :

1)
#include <iostream>
using namespace std;
void func1() {
cout << "Func1" << endl;

[Code] ....

Why ptr_func1() does not work here?

IntelliSense: expression preceding parentheses of apparent call must have (pointer-to-) function type

2) How can i pass func1 to func2 as parameter?

I tried void func1(void* function), but I think I'm wrong here.

View 2 Replies View Related

C++ :: Passing Array As Argument To Function?

Feb 10, 2013

how can i pass an array as an argument to the function? in getCoin() fcn, I am supposed to pass coins array as an argument to the function. fcn prompts user to enter coin(Date, Type and Country). values entered by user are read and assigned to the coins array. I tried the code below.

//# include "Coins.h";
#include <iostream>
#include <string>
using namespace std;

[Code].....

View 4 Replies View Related

C++ :: Using API Function That Has Char Pointer As Argument

Feb 5, 2014

I am using a small robotic-car that is controlled by writing C/C++ codes under Linux. I need to use a particular function from the library provided by the manufacturer. The relevant API documentation for the function is:

BASEBOARD_ERROR_KIND ZMP zrc :: :: :: Baseboard GetRS232Data (char * msg )

RS232 data acquisition.

Argument:
[Out] msg Address of the acquired data.

Returns:
BASE_OK RS232 data acquisition success
BASE_BASE_232_GETDATA_ERR RS232 data acquisition failure

I have trouble writing the relevant code in the main program that invokes this function. Here is a snippet of what I have tried:

# include "Baseboard.h"
int main () {
Baseboard _Baseboard; // Class name is Baseboard
char *msg ;

[Code] ......

The part where I am uncertain is how to handle the char pointer "msg" in the declaration, function call and referencing. According to the documentation, the char pointer "msg" is the output of the function so I presume that is is somehow dynamically allocated. Am I handling the char pointer properly in the declaration, function call and referencing parts?

Another related question I have is: I am printing out the value of the variable "dummy". I always get 0 for it. Since the variable "dummy" is an enum of type BASEBOARD_ERROR_KIND which can take on two values (first value represents success and the second failure), it is alright to get a integer value of 0 for it if the function call was successful ? (I do not have much experience with using enums so this is a enum-related question on whether we can get an integer value representing the first enum value) .

View 2 Replies View Related

C++ :: Void Pointer Argument In A Function?

Jun 11, 2014

Why does the following code compile and execute without any error? I mean, the function compareid should get 2 arguments so why does the compiler not complaining, is it because of the type of arguments?

Code:
#include <stdio.h>
int compareid(void* info, int value); // ansi declaration
int compareid(void* info, int value)

[Code] .....

View 5 Replies View Related

C++ :: Function Having Argument As A Pointer Passed By Reference

Dec 8, 2014

I have to write an example in which you use a function having as argument a pointer passed by reference in C++. Can you provide an example like this:

funz.h : void funz( int *&a );
funz.cpp : ? (1)
main.cpp:
#include "funz.h"
#include <iostream>

[Code]...

as I write in (1) and (2) ?

View 5 Replies View Related

C++ :: Invalid Use Of Template Name ND Without Argument List

Dec 31, 2013

#ifndef BSTCLASS_H_
#define BSTCLASS_H_
#include <string>
using namespace std;

[Code]....

-'ND' is not a type; when I use it as a parameter
or
-invalid use of template name 'ND' without argument list; when I use it as a return type.

On some lines I try access the elements inside of 'ND' variables and I get errors saying that those elements don't exist for the given pointers.

View 4 Replies View Related

C++ :: No Constructor Matches Argument List

May 1, 2013

These are the two errors I get...

Error1error C2664: 'ProductionWorker::ProductionWorker(std::string,int,std::string,std::string,double)' : cannot convert parameter 4 from 'int' to 'std::string'c:usersfred steinmandocumentsvisual studio 2010projectsemployee and productionworkeremployee and productionworkeremployeeproductionworker.cpp14
2IntelliSense: no instance of constructor "ProductionWorker::ProductionWorker" matches the argument listc:usersfred steinmandocumentsvisual studio 2010projectsemployee and productionworkeremployee and productionworkeremployeeproductionworker.cpp14

#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using namespace std;
class Employee {

[Code] ....

I get a red line under the John Doe part.

View 1 Replies View Related

C++ :: Creating A Linked List Of Common Elements From Two Other Linked Lists

Apr 29, 2013

I'm trying to write a function that takes two linked lists and creates a third one with only the common elements.

It assumes the first list (the caller) has no dups, but it doesn't seem to be working. The program doesn't crash, it just hangs when it is supposed to display L3 (the third list)..everything else runs and is displayed fine.

template <typename T>
LList <T> LList <T>:: common (LList <T> &B)//common fct
{
Node <T> *hunter1 = Head;

[Code]......

View 10 Replies View Related

C++ :: No Instance Of Constructor Matches Argument List

Mar 2, 2013

While writing a code for Blackjack game in the function which makes a standard deck i am getting this message "no instance of constructor matches the argument list" I am going to show my Card.h,Hand.h, Deck.h and Deck.cpp.

Card.h
//#ifndef CARD_H
//#define CARD_H
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <vector>
using namespace std;

[Code] ....

View 7 Replies View Related

C++ :: Invalid Use Of Template (Array) Without Argument List

Jan 24, 2014

I'm getting a template error.

Error

Code:
/data/data/com.n0n3m4.droidc/files/temp.c:92:3: error: invalid use of template-name 'Array' without an argument list
Array::Array(int s): size(s)
^
compilation terminated due to -Wfatal-errors.

Code:

// headers
#include <iostream>
#include <utility>
#include <cctype>
// stuff we need from namespace std
using std::cout;
using std::cin;

[Code] .....

View 2 Replies View Related







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