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


ADVERTISEMENT

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 :: Create Array Of Pointers To Pointers Which Will Point To Array Of Pointers

Feb 28, 2014

I'm trying to create an array of pointers to pointers which will point to array of pointers (to strings) I tried

Code:

int i;
char *string[]={
"my name is dave",
"we like to dance together",
"sunny day",
"hello",

[code]...

the app keeps crashing , I don't know how to make the array-elements to point to another array-elements..

View 4 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 :: 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 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 :: Parsing Char Array To Array Of Struct To Process Packets

May 28, 2013

I wrote this simplified version of a program i am writing that parses data in UDP packets. In the process of doing so i pretty much answered all my questions and fix all the problems i was having.

decodeSystemMap function will be in loop, and will proccess packets that have mostly the same data, only a few items will be added or changed or deleted.

whats the best way to check if there are any new, deleted, or removed items in the packet and only modify those?
Is there anything unsafe / dangrous about the way the code is now?

Code:
/* * File: main.c
* Author: david
*
* Created on May 23, 2013, 11:57 AM
*/

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

[Code] ....

View 4 Replies View Related

C++ :: Allocating Array Of Pointers To Dynamically Allocated Array?

Jan 18, 2014

I'm trying extremely hard to understand pointers and I have the basic concept down.. I feel as though my knowledge of dynamically allocated pointers and pointers in general is not enough to understand the logic behind what I'm trying to do. The problem is that the donations array must be able to accept any number of donations. I've made it do just that, but there is also an array of pointers which must each point to the same element in the donations array. The program works if I assign int *arrPtr[100] for example, but it does not work if I try to dynamically allocate it to accept the same number of elements for donations entered by the user. Here it's the snippet

#include <iostream>
using namespace std;
//Function Prototypes

[Code]....

View 2 Replies View Related

C/C++ :: How To Initialize Array Of Pointers To Array Of Characters

May 21, 2014

I am trying to initialize an array of pointers to an array of characters, I can do it in 3 lines but I really want to do it in one line at the same time keeping the #define.

3 lines initialization (can compile)
======================
#define A 1
#define B 2
char row1[] = {A|B, B, A};
char row2[] = {B, A};
char *test[]= {row1, row2};

1 line initialization (failed)
===============================
char *test[] = { {A|B, B, A}, {B, A} }; // <- how do i do this??

I do not want this because it waste ROM space
=============================================
char test[][3] = { {A|B, B, A}, {B, A} };

View 18 Replies View Related

C :: Passing Struct Through Array

Apr 2, 2013

I am trying to pass a struct through an array to another array from one microprocessor to another microprocessor and then dereference that array to update the same exact struct on the other microprocessor.My goal is to always have values inside of both structs while sending any updates to the struct on the other microprocessor in the mean time but I seem to be looping through the data and the members of the struct seem to be cleared out after every clock cycle. I can verify this by the flashing of my leds which the struct controls.

FIRST MICROPROCESSOR

Code:

extern struct i2c_data * TX_Data;
extern struct i2c_data TX_Data_1;
extern struct i2c_data TX_Data_2;
}

[code]....

View 1 Replies View Related

C++ :: Array Of Struct Initialization

Apr 4, 2014

In a book I'm reading, the author has the following struct:

struct VertexPos {
XMFLOAT3 pos;
};

Where XMFLOAT3 is a structure with x,y,z floating point values within. He declares and initializes an array as the following.

VertexPos vertices[] =
{
XMFLOAT3(0.5f, 0.5f, 0.5f),
XMFLOAT3(3.3f, 5.6f, 3.6f),
XMFLOAT3(-4.5f, 2.2f, 6.4f)
};

It doesn't make sense to me why this is working. The way my mind is thinking about this is that vertices is an array of type VertexPos, so then why can it be initialized with objects of type XMFLOAT3?

View 2 Replies View Related

C++ ::  Length Of Array Of Struct

Jan 23, 2015

I'm trying to make an application and I need the length of the array of a struct. Like this:

struct myStruct {
int integer;
};
myStruct struct[] =
{
1,
2,
};

I want to get how many ints are in the array...

View 2 Replies View Related

C++ :: Reading A File Into Array Of Struct

Nov 20, 2014

Code:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
struct inventory

[Code]...

This is my program output Enter the file name : "filename".txt ..... (Nothing shows up)

View 3 Replies View Related

C :: Allocating Memory To Array Of Struct?

Sep 9, 2013

Do you have to allocate memory(malloc) for an array of structs? Example:

Code:
typedef struct{
char * name;
}First;
struct name{
First fname;
};
struct name Names[10];

View 7 Replies View Related

C :: Searching Array Of Struct Students

Feb 28, 2013

I have to search an array of struct students on the basis of their first names, last names and roll numbers .. so far i am done with the input of the student first , last names and roll numbers . I have problem in searching the array ..

Code:
#include <iostream> Code: #include <string>
using namespace std;
struct Student {
string FirstName ;
string LastName ;

[Code] ....

View 5 Replies View Related

C++ :: Using Struct / Char Array For Tic Tac Toe Game

Feb 11, 2014

I basically just want a function that tells me if 'X' or 'O' won in a tic-tac-toe game. I don't care about the visuals, I just want a function that tells me if 'X' or 'O' won. If X wins, return 0. If Y wins, return 1.

How to do the diagonals, but as far as the across and down wins, I know I have to use a nested for loop, but am a little stuck, as to exactly how to set it up.

#include <iostream>
using namespace std;
struct TTT{
char array[3][3];
unsigned moves;

[Code] ....

View 1 Replies View Related

C++ ::  Static Member In Struct Array?

Jun 25, 2013

Here's the definition of my struct:

struct Speaker {
static int numElem;
string name;
int number; // Phone
string topic;
float fee;
};

// IN main() FUNCTION
Speaker s[10];

The goal is for numElem to keep track of how many of the 10 elements are in use. However, I'm not sure the proper way to access the element, if it's even possible.

View 7 Replies View Related

C++ :: Reading A File Into Array Of Struct

Nov 21, 2014

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
struct inventory {
int barcode;
char description[512];

[Code] ....

This is my text file
20123451
Sugar packet (1 kg)
2.50
560
21347652
Milo 3-in-1
12.50
200
20123453
Salt (1kg)
4.50
270
21347654
Nescafe 3-in-1
12.50
400
20123455
Tamatoes
4.00
100
21347656
Cucumbers
4.00
280

This is my program output
Enter the file name : "filename".txt
..... (Nothing shows up)

View 1 Replies View Related

C++ :: Deleting A Record From Struct Array?

Aug 31, 2014

I want to delete selected records from struct array using cstring reading from files. Here I read my records to stud struct then assign non-deleted to stu struct but its not deleting as desired...strcmp is giving 25

while(cont=='Y'){
cout<<"Enter student ID to delete: ";
cin.ignore();
cin.getline(id, 15,

[Code] ....

I did some debugging effort and I found here is the problem..the stud[0].ID and id is not same but why? I am giving in same id and both char array lenght is 15

while(cont=='Y'){
cout<<"Enter student ID to delete: ";
cin.ignore();
cin.getline(id, 15);
cout<<strlen(stud[0].ID)<<" "<<strlen(id)<<endl;///---> lenght 1 is 10
///---->lenght 2 is 8
cout<<strncmp(id,stud[0].ID, 10 )<<endl;

View 2 Replies View Related

C++ :: Allocation / Deallocation Of Array Within Struct

Feb 27, 2013

Okay so I have a question. Lets say I want to create arrays of exact size for abstract data type members. For example:

struct student {
char name[10];
int idNumber;
};

My question is how to declare this array as null so that later i can give it an exact size to match the length of the name. if it were not a part of the struct i would imagine that the code would look something like this:

char * name = NULL;
name = new char[10];

View 4 Replies View Related

C/C++ :: Accessing Elements Of Struct Array

Dec 9, 2014

I've been working for some number of days on this code to take information about movies from both a file and the user, store the infos in an array of structs, and at the end, write all the info out to a file. I'm having some problems with an error message reading:

"prog.c:102:11: error: subscripted value is neither array nor pointer nor vector"

this error occurs in many lines (which I will label specifically below -- they are everywhere where I am trying to access/modify an individual element of a struct element of the array).

A few examples of where I am having the problems are lines:
39, 52-55, 70, 72, and 86 (and more of the same exact variety).

I am obviously rather systematically doing something wrong, but I am quite certain all of these are the exact same mistakes.

I pull up also 2 or 3 other errors, but I don't think they are related and should be able to fix them quickly once I work out this conundrum.

#include <string.h>
#include<stdlib.h>
#include <stdio.h>
int moviecount =0;
typedef struct{
int year;

[Code] .....

View 5 Replies View Related

C++ :: Passing Struct Array In Function

May 5, 2013

Here's my code : [URL] .....

You should be able to enter those fields, and after some time when while loop is stopped (when u press n) it should print out that PhoneBook bellow. I don't understand what is the problem but I think it is that Display function.

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 :: Array Of Pointers To Strings

Mar 6, 2015

I'm wondering how to access Buffer 1 and 2 via the pointer array;

Code:
char *BufPtrs[3];
char Buffer1[64];
char Buffer2[64];
BufPtrs[0] = Buffer1;
BufPtrs[1] = Buffer2;
BufPtrs[2] = NULL;

I thought that if I were to access Buffer1 via BufPtrs[0], I would simply just put an * to it before printf()-ing or store it in a char[] (equivalent to a string).

View 2 Replies View Related

C :: Array Containing Pointers To Structures?

Aug 9, 2013

How do I store pointers to a struct in an array ? I am using sprintf to concatenate some values together and then output it to an array in its 1st argument. A portion of my code is shown below.

Code:

int count = 0;
struct addx {
int a;

[Code].....

View 1 Replies View Related







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