C :: Unable To Return Struct Node Without Using Pointers

Jul 20, 2014

I'm quite new to C and these days I have been playing around with a linked list. I managed to make a working version using pointers, ad only for the sake of learning I was trying to do the same thing just passing the "Object reference" Here is the method that apparently doesn't work..

Code:

struct Node addNode(struct Node head){
int value;
struct Node *n;
printf("Please enter the value
");
scanf("%d", &value);

[Code]...

when I return the function i have something like: head=addNode(head)

Unfortunately it does not work the way I aspect. I suppose that there is something I have left out..

Code:
like n->next=&head
// passing the address of the head at the next pointer of the struct
head =*n
//copy the values of the new node to the old head..

There must be something wrong with this line.. return head; What have I done wrong?

View 2 Replies


ADVERTISEMENT

C++ :: Creating A Struct Within Struct Node?

Feb 28, 2015

Im having trouble creating a struct within a struct node. the program suppose to hold students firstname, lastname, and gpa in a node therefore creating my linked list. Line 26 keeps saying that cannot convert parameter 2 from 'studentType to std::string

#include <iostream>
#include <string>
using namespace std;
struct studentType{
string firstname;
string lastname;
double gpa;

[code].....

View 2 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++ :: Return A Node Using Recursion

Mar 27, 2013

So the task is to find the node with minimum value of a binary tree (not binary search tree). the input is the pointer to the root of the tree. and i cannot make recursion work when i do if conditions. here is what i have Code: ​/*function 3-takses as input the pointer to the root of the tree and returns a pointer to the node with the minimum value*/

CPPtr minimumvalue(CPPtr SP){
CPPtr min = NULL; //node of minimum value
if(SP== NULL){ // if there is a node, begin comparing
return NULL;
}
else{
if(SP->data<SP->left->data){ //if the node has smaller value than its left child
min = SP; //update node of minimum value

[code].....

no matter where i call my function i get errors like unhandled exception at some memory. how to use recursion in this?

View 6 Replies View Related

C++ :: Want To Return A Node Using Recursion

Mar 28, 2013

So the task is to find the node with minimum value of a binary tree (not binary search tree). the input is the pointer to the root of the tree. and i cannot make recursion work when i do if conditions. here is what i have

CPPtr minimumvalue(CPPtr SP){
CPPtr min = NULL;//node of minimum value

if(SP== NULL){// if there is a node, begin comparing
return NULL;

[Code] ....

No matter where i call my function i get errors like unhandled exception at some memory. How to use recursion in this?

View 1 Replies View Related

C/C++ :: How To Use Node Struct In Test Driver

Jul 24, 2014

I have a file system class that has a struct named Node declared private as so:

class FileSys{
private:
struct Node {
Node* next;
Node* prev
Node* parent;
int key;

[Code] ....

But how would I get to the Node struct? I tried to do this in the main but of course I received an error:

FileSys FS_Obj;
FS_Obj Node* T = new Node;

With errors:

Error: expected ; before Node
Error: Statement has no effect

View 9 Replies View Related

C/C++ :: Node Data Return Type?

Apr 7, 2014

In my main I have a do/while loop, which is to iterate around the method calculateImportance while i is not equal to the numNodes.

do
{
int i;
int numNodes = Test.count();
for(i=0; i<=numNodes; i++)

[Code]....

I have been messing around with the data type node, hence why it is there are present, but, that doesn't seem to the answer

This is the function declaration in the header file.

node CalculateImportance();

View 1 Replies View Related

C++ :: Unable To Convert Parameter To Struct Type

Nov 3, 2013

I am trying to make a automated menu. It shows there are no syntax errors but when compiled it says cannot convert choice from type into to menuItemType. I am not sure what I did wrong. Here is the code

Code: #include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct menuItemType
{
string menuItem;

[Code]...

View 7 Replies View Related

C :: Unable To Pass Struct As Input Argument

Nov 11, 2013

Something is wrong when i try to pass the struct as a input argument

Code:

#include <stdio.h>
#include <string.h>
#define MAX 20
void printBook(cataT book);
int main(void){
typedef struct cataT{

[Code]...

View 4 Replies View Related

C :: Unable To Pass Values To Struct As A Byte

Jul 19, 2014

I am using a struct and tying to send values to it as byte value

Code:

#include<stdio.h>
typedef struct{
unsigned r1:1;
unsigned r2:1;
unsigned r3:1;

[Code] ....

Error: invalid suffix "b00100000" or incompatible types in assignment

I am able to access the member as Range.r1 = 1; and have no problems. I want to send data whole at once, but how ?

View 8 Replies View Related

C++ :: Unable To Sort Array Declared As Struct

Jan 16, 2014

I am trying to sort an array declared as a struct but it doesn't work. What am i doing wrong?

#include <iostream>
#include <fstream>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
int n;
struct film

[Code]...

View 1 Replies View Related

C/C++ :: Unable To Find The Distance Between Two Void Pointers

Jul 13, 2014

I am trying to find the distance between two void pointers, so I can follow this distance to a certain pointer in a vector when given only the previous element in that vector.

int distance = (char*) prev - (char*) first;
next = (char*) cv->elems + cv->elemsz + distance;

Basically, prev and first are void pointers. I am trying to cast them into a char, subtract the first element in the vector from the previous one, and then use this distance to determine what the next element in the vector is. However, it is not working. I am not sure how to do this. To complicate matters, prev is a const void *.

View 7 Replies View Related

C :: Array Of Pointers To A Struct?

May 10, 2013

I am working on an assignment identical to another post from a couple years ago, for reference here is the thread:

array of pointers to structures sorting addresses by zip code

They way it is written on that thread is almost identical to the way the teacher implied to have it done (only wrote part of the input block). But I am having an error:

When it gets to the output section it outputs then next name along with the zip code... I tried strncpy and strxfrm but both cause more problems than they did work.

The last part of the project is to have the output put out in order of least zip code to most zip code (00000<99999), so this is causing me a real problem and I do not see what exactly is making this happen.

Here is my code (we dont HAVE to use gets but professor suggested using it for this assignment, next lab is to rewrite this using files and fgets rather than I/O redirection):

header.h Code: #ifndef lab_6b_7b_Header_h
#define lab_6b_7b_Header_h
//header file intiating other headers
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{

[code]....

I have not started the sorting code because I cannot get past this, but once I have proper zip codes I am sure I can make a sort function no problem.

I am using xcode with some breaks to read variables as various points and do not notice anything wrong until it makes it to the output functions, although this page briefly pops up between input and output functions when the breaks are up:

View 8 Replies View Related

C++ :: Template Return Struct Fields

Dec 2, 2014

is it possible to define as template the following get functions.

class Config {
public:
enum { NO_ID = 999 };
struct ValueType {
bool a;
size_t b;
std::time_t c;

[code]....

View 6 Replies View Related

C :: Bsearch In Array Of Pointers To Struct

Mar 6, 2015

What I'm trying to do with this code is an address book and I have an array of pointers which are returned by malloc whenever I need to add an extra entry in the address book. What I need to do is search for a specific entry using bsearch. I've got an inqSort() function that sorts the table and runs normally, but my program crashes when I try to use bsearch.

Code:
typedef struct {
char name[20];
char phone[14];
} abEntry;

[Code] ....

Every time an entry is inserted, I inqsort() the array so it's always sorted, and it works as expected. But when I try to call findEntryUI(); from the main() function, the program crashes after entering the name I want to search.

View 3 Replies View Related

C :: Using Typedef Struct And Passing Pointers To Functions

Mar 3, 2013

I am having problems with passing my values through functions.

Here is my code:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void test(int**);
void test2(int**);

[Code]....

View 8 Replies View Related

C :: Linked List - Change Struct Pointers

Dec 17, 2013

I have a linked list where each node contains a pointer to a string, I'm treating the linked list as a text file and each node/string contains each line in the text file.

I have all of that working, but now I need to create a switchLine function that takes in the two line numbers and I need to switch those lines in the text file. I initially thought of switching the pointers to each the next node in the linked list such that the node order changes, but I then realized how much work that would actually take when you need to consider so many cases. So I instead thought of changing the pointers to strings. If I want to switch the 2nd and 3rd line, then I'd want to have the 2nd node in the list have its char * pointer point to the memory position that the 3rd node's char pointer points to, and vice versa.

View 2 Replies View Related

C++ :: Accessing Pointed-to Value In A Struct Vector Of Pointers?

Apr 30, 2013

I have a vector (structures) in a struct (instances). I make a declaration of this struct called instance. The vector is a 3-layer vector of pointers, like so:

vector < vector < vector<scene::IAnimatedMeshSceneNode*> > > structures; (The type is from Irrlicht 3D). I have 3 nested "for" loops which looks similar to the following:

for (int a = 0; a < instance.structures.size(); a++) { /*note:vector size previously set*/
for (int b = 0; b < instance.structures[a].size(); b++){
for (int c = 0; c < instance.structures[a][b].size(); c++) {

if (1) { //checking value of variable not included in snippet

(instance.structures)[a][b][c] = smgr->addAnimatedMeshSceneNode(fl);
(instance.structures)[a][b][c]->setPosition(renderPos);
}
}
}
}

The problem is in these two lines, I think:

(instance.structures)[a][b][c] = smgr->addAnimatedMeshSceneNode(fl);
(instance.structures)[a][b][c]->setPosition(renderPos);

These are currently referencing the pointers, it seems. The program compiles but crashes at this point. I need them to reference the values of the pointers. Problem is, I don't know where to put the dereference operator (*). Where should it go?

View 4 Replies View Related

C :: Return Struct From DWORD (unsigned Int) Thread In Windows

Jul 12, 2013

In windows thread function not a void (as pthread in Linux).

Its type is DWORD(unsigned int) so my question is

How to return a struct (contain alot of different data types) from DWORD (unsigned int) thread in windows?

Code:
#include <windows.h>
#include <stdio.h>
#include <conio.h>

typedef struct {
char* name;
int id;

[Code] .......

View 12 Replies View Related

C++ :: Return Struct Pointer From A Void Function And Print

Mar 17, 2013

i need to return a struct pointer dynamically allocated inside a function call void function() which is done using 'out parameters' in following code

struct my_struct {
int x;
} void my_function( my_struct** result ) {
my_struct* x = new my_struct{ 10 };
//...
*result = x;
}

Now i have a doubt, so if i want to print the return value from struct pointer, should i need to print it in the void function() or in the caller the function...

View 3 Replies View Related

C++ :: Using Pointers With Function Both As Arguments And Return Type

Jan 29, 2015

I always have confusions while using pointers with functions both as arguments and as return type.

View 1 Replies View Related

C# :: Treeview Node Selection Show First Node Of Tree Instead Of Selected

Apr 22, 2015

I am working on C# Project [Windows Form Application], to update treeview nodes from excelsheet [xls] Cell [row i, Column 3] Values, while on selecting treenode, it should update corresponding Column 4 Value [row i, Column 4]. For me, Treenode are populated successfully, but on selecting the treenode, it always display first Element of treenode [Not selected one].

Populated Treenode from Excel as: [ Update Child Nodes from Column 3 elements [Column 2 Contain Parent node name and Column 3 have Child Node name], if Column 2 Value is same as Parent node name [My Module], update the child nodeunder same Parent node.]

for (int i = 0; i < worksheet.UsedRange.Rows.Count; i++) {
string mynode = ((Excel.Range)worksheet.Cells[i + 1, 3]).Value2.ToString();
string mynode2 = ((Excel.Range)worksheet.Cells[i + 1, 2]).Value2.ToString();

[Code] ....

On selecting the Child Node, it always give 1st Parent node. Instead of Selected Node.

for (int i = 0; i < worksheet.UsedRange.Rows.Count - 2; i++) {
string mynodetext = ((Excel.Range)worksheet.Cells[i + 2, 3]).Value2.ToString();
string mynodetext1 = ((Excel.Range)worksheet.Cells[i + 2, 4]).Value2.ToString();
if (treeView1.SelectedNode.FirstNode.Text == mynodetext) {
this.richTextBox1.SelectedText += Environment.NewLine + mynodetext1 + Environment.NewLine;
}
}

How to get correct selected Node.

View 2 Replies View Related

C# :: Why Is Node Click Event Changing The Node Icon

Jul 26, 2014

I'm having a hard time figuring how to get my imagelist index 3 icon to display in the nodes "N1" and "V Speeds" below? So, as you can see in the attachment, the closed folder icon is currently shown which is index 0 in the imagelist. But I want index icon 2 to show in these two nodes.

treeView.BeginUpdate();
treeView.Nodes.Clear();
treeView.Nodes.Add(new TreeNode("Checklist"));

[Code].....

View 12 Replies View Related

C Sharp :: How To Get Text From Node In XML File That Contains Text And Child Node

May 21, 2013

I have a very big xml file. I read it using by xmlReader. I have problem when i reach to next line:

<title>Abasia<nemod>(-astasia) (hysterical)</nemod></title>

How I can read all that content. I have to have next string at the end: "Abasia (-astasia) (hysterical)".

I tried to use ReadElementContentAsString() for all elements, but elements like this has exception, because it has child element.

View 1 Replies View Related

C/C++ :: Sizeof (struct) Returns 6 More Bytes Than Actual Struct Size?

Sep 14, 2014

#include <stdio.h>
#define MAX_USERS 20
struct {
char ID[10];
char Name[40];
int Pos;

[Code] .....

I was attempting something weired with address to move data around when I discovered that the size of the array is not what I expected. I am passing this structure as &Users to a function that declares it as a void *, then I can deal with chunks of data (memmove) and not have to worry about index or things like that. However...sizeof is returning something I do not understand.

View 9 Replies View Related

C :: Will Return Root Statement At End Ever Return Value Other Than Value Passed To Function?

Mar 29, 2013

I'm writing some functions pertaining to binary trees. I've used recursion once before while learning quicksort but am still quite new and unfamiliar with it. And this is my first time touching a binary tree. So my question: In my addnode function, will the return root statement at the end ever return a value other than the value passed to the function?

Code:

#include <stdlib.h>
struct tnode
{
int data;
struct tnode * left;
struct tnode * right;
}

[code]....

View 4 Replies View Related







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