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


ADVERTISEMENT

C/C++ :: Return From Incompatible Pointer Type

Jul 13, 2014

/*
* symboltable.c
*/

#include "symboltable.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "include/utlist.h"

[Code] ....

View 2 Replies View Related

C/C++ :: Warning / Assignment From Incompatible Pointer Type

Apr 17, 2014

I'm working on a program and everything works except for the follow function:

void swapHex(int x, int byte1, int byte2) {
unsigned char *b1, *b2, tmpc;
printf("%d in hex is %x
", x, x);
printf("swapping byte %d with byte %d
", byte1, byte2);

[Code] ....

I get the following errors when compiling:

In function "swapHex":
warning: assignment from incompatible pointer type
warning: assignment from incompatible pointer type

View 2 Replies View Related

C/C++ :: Error - Initialization From Incompatible Pointer Type

Apr 8, 2012

Below is my code snippet.I'm getting "Error:initialization from incompatible pointer type" error on line 'int *q = status;'.

Obviously, I'm missing something but has no clue...:(

void findwalls(int *p,int y,int x){
int status[y_count][x_count][4];
int *q = status;
for(int i = 0;i < (y_count * x_count * 4);i++)
*(q + i) = *(p + i);

View 1 Replies View Related

C :: Function To Read A Text File - Incompatible Pointer Type

Nov 3, 2014

So for a project, my professor sent out two pages of code containing functions to read a text file (since we do not know how to write this on our own yet). I've got the code working on Orwell IDE and it gives me 2 warnings saying

"Passing argument 1 of 'readFromFile' from incompatible pointer type"

"Passing argument 2 of 'option2Print' makes integer from pointer without a cast"

The Orwell IDE seems to just bypass these warnings and compiles the code correctly. However, when I transferred my files over to my desktop using BloodShed (what the professor uses), instead of getting a warning I get an error and the code won't compile.

I assume it will not compile on his computer either since he uses the BloodShed IDE.

I don't know how to put the code directly into the text neatly, so a attached a .zip file with my code. The "storms.txt" file is also included. (the file that will be read).

View 4 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 :: 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++ :: Passing Arguments From Incompatible Pointer Type - Warning In Function Call Transpose In Main Routine

Jun 4, 2013

#include <stdio.h>
#include <stdlib.h>
int size_b_row1;
int size_b_col1;
int main(void) {
double C[4][4] = {{1,3,5,2},{7,6,2,2},{1,2,7,3},{2,3,5,3}};
double TC[4][4];
transpose(C, TC);

[Code] ......

View 2 Replies View Related

C :: Errors For Incompatible Types In Return

Oct 23, 2013

I am writing a program in C. The following is an extract from my code:

Code:

enum coin_types{
FIVE_CENTS=5,
TEN_CENTS=10,
TWENTY_CENTS=20,
FIFTY_CENTS=50,
ONE_DOLLAR=100,
TWO_DOLLARS=200

[Code] .....

I'm getting the following errors:

For: new = new_coins_data_line(line);
"Incompatible types in assignment"

For: return newdata;
"Incompatible types in return"

There seem to be problems with my variables and perhaps it is related to the type 'struct coin' which has an enumerated type within it.

View 5 Replies View Related

C++ :: Doubly-Linked List And Referencing Errors?

Oct 4, 2014

We had to convert a single-line text editor which uses arrays to one that uses OOP and double-linked lists and I have been doing it in steps. I have, for the sake of convenience, put my headers, implementation and main all in one file.

I'm compiling this program in Hercules (the getch function uses C code).

I keep getting the error from the compiler saying "Undefined Symbol" for functions:

insertNode(char, Node);
deleteNode(Node*);
insertHead(char);

The full message is: ld: fatal: Symbol Referencing Errors. No output written to a.out collect2: ld returned with 1 exit status.

// A fake single line text editor program.
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <unistd.h>
#include <termios.h>
//#include "main.h"
typedef char Letter;

[code]....

View 3 Replies View Related

C++ :: Logging In Multiple Files - Compilation Errors

Sep 25, 2014

I am working on one application that requires extensive logging so I want to create a log file of each day during execution.

I tried easylogging++ but i am unable to use into multiple files. If i try to use in other file. I get compilation errors of using same functions or methods already defined.

How can i use macro to hide the implementation of logging in one class to other ??

View 1 Replies View Related

C++ :: Compiler And Linker Errors For Linked List Class And Application

Aug 31, 2014

I am trying to write a program that will take a list of integers from a file and write them to another text file. I've been banging my head at this for days trying to get it to compile as it is riddled with linker and compiler errors.

**************************header*************************

#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <iostream>
using namespace std;
template <class T>
class linkedList {

[Code] ....

View 6 Replies View Related

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++ :: Initializing Generic Type That Can Be Both Primitive And Object?

Apr 1, 2013

I have defined my own class, Queue, which inherits from my own class, LinkedList. I have been using templates to allow Queues to be of int, string, etc types.

But now I want to be able to store objects in my Queue type. And so the problem I have is that in my LinkedList class, I have two instances where I initialize an instance of my generic type T to 0.

For instance, the removeFirst() method starts like this:

template <typename T>
T LinkedList<T>::removeFirst() {
T a = 0;

And so the compiler complains that it can't convert from int to [in this case] Command&.

What to do?

View 2 Replies View Related

C/C++ :: Stack Class For Generic Type Data

Feb 4, 2014

I'm trying to implement my own Stack class, for a generic data type. Here is what I have so far, but I'm having problems compiling the code:

Stack.h:
#ifndef STACK_H
#define STACK_H
#include <vector>
template< typename T >
class Stack {

[Code] .....

View 5 Replies View Related

C++ :: Can Use Templates To Make A Multi-type Linked List?

Apr 28, 2014

If I wanted an int connected to a float connected to a string connected to a POD, would all I have to do is :

Code:

template<class T, class X>
struct node {
T data;
node<X> *next;
};

Or would I be forced into using polymorphism?

View 10 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 :: Incompatible Integer To Pointer Conversation

Nov 28, 2013

I am getting error"incompatible integer to pointer conversation..." and don't know how to fix this. In my code, user inters line like this (3+3*(55-52)) I need to separate number from the line so I can do other operation.here is my code

Code:

#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main(){

[Code]....

View 1 Replies View Related

C/C++ :: Creating Singly Linked List / Loading Class Type Array

Aug 6, 2014

I've written this class and struct to create a singly linked list. The data is stored in the binary file which I've opened and read. I'm trying to load said data into a class type array. The errors I'm getting are "incompatible types in assignment of 'StatehoodInfo' to char[3]" Lines 130-134 is what I was working on.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring> //For char[] string functions

[Code] .....

View 2 Replies View Related

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 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++ :: 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







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