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


ADVERTISEMENT

C++ :: Vector Of Void Pointers Which Point To Array Of Characters

Jan 21, 2014

This code work perfectly, as follows.

Code #A:

#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
typedef std::vector <void *> gr_vector_void_star;
gr_vector_void_star output_items;

[Code] .....

Output of above code #A:

char * sentence = "Angel";
for (int i=0; i < 5; i++)
{ out[i] = sentence[i]; } // error: invalid conversion from 'char' to 'char*' [-fpermissive]

It fails to compile with error message "invalid conversion from 'char' to 'char*'".

View 19 Replies View Related

C++ :: Create Program That Displays Median Of Array Using Pointers

Feb 27, 2013

The assignment is to create a program that displays the median of an array using pointers. Assume the array is already in ascending or descending order.I'm getting errors currently on the bottom two "return median;" statements.The code that I have so far is as follows...

#include <iostream>
using namespace std;
char again;
int getMedian(int*, int);
const int constant = 100;

[code]....

View 3 Replies View Related

C/C++ :: Create Billing System Without Using Pointers - Array Calculations

Feb 17, 2014

I am trying to create an billing system "without using pointers". This is my class assignment. In this,

1) User inputs the name
2) The system asks how many items he has purchased
3) Displays a bill number [just a random number]
4) System asks for the item names the user purchased and stores them in an array (of max 10 (ten) inputs (or items))
5) After each item the user inputs, the system asks for the price of the item (stored in an array of numbers)
6) The total bill is calculated, by adding the sum of all prices in the array

I am having terrible difficulties in coding #4 and #5. Somehow, they aren't going well together. Here's what I have:

#include<stdio.h>
#include <stdlib.h>
int main() {
char item[10][10], answer = 'y', name;
int price[10], total_item, total_price = 0, i, j, a, total_bill = 0, max_items = 10, max_char = 10;

[Code] ....

You might find a lot of unused variables

View 10 Replies View Related

C++ :: Creating Array Of Pointers To Base Class To Point To Derived Class Objects Dynamically

Jan 16, 2013

Please consider the following code :

#include <iostream>
using namespace std;
class superclass;
class subclass1;
class subclass2;

[Code] ....

As you can see I want to create a dynamically allocated storage of references to a parent class each of which can then point to a child class, how ever I do not know how to extract the child class out again from that array so i may access its variable b.

View 2 Replies View Related

C++ :: Comparing Char Pointers To Integer Pointers

May 21, 2013

I am a little confused while comparing char pointers to integer pointers. Here is the problem:

Consider the following statement;
char *ptr = "Hello";
char cArr[] = "Hello";

When I do cout << ptr; it prints Hello, same is the case with the statement
cout << cArr;

As ptr and cArr are pointers, they should print addresses rather than contents, but if I have an interger array i.e.
int iArr[] = {1, 2, 3};

If I cout << iArr; it displays the expected result(i.e. prints address) but pointers to character array while outputting doesn't show the address but shows the contents, Why??

View 2 Replies View Related

C :: Point Of Function Pointers

Sep 27, 2014

I'm wondering about the point of pointers to functions. When is it used?I saw the below example. It doesn't make sense to me. I mean we can easily write code that does the same without having to use pointers.

Code:

#include <stdio.h>
int addInt(int a, int b); // Adds 2 integers
int add5to4(int (*function_pointer)(int, int));
int main(void)
{
int sum;
int (*function_pointer)(int, int);
}

[code]....

View 2 Replies View Related

C++ :: Pointers Point To Address In Memory

Sep 30, 2013

Pointers point to an address in memory. What if I used 3 pointers: 2 to mark the first/last nodes, and the third to mark the current node being referenced? I would wrap it in a class (to make the memory management automatic, of course), but is this practical?? maybe some pseudo code will get the juices flowing:

template<class type>
class supercondensed_list{
public:
supercondensed_list();
~supercondensed_list();

[code].....

Any things I should take into consideration? I'm not exactly the most experienced with pointers, and manually managing memory, but I think it's worth trying. If this works, then my programs should, in theory, be 100% memory efficient.

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

C++ :: Using Array Of Pointers To Objects?

Sep 27, 2013

I've created an Array of pointers to objects using:

Person ** A = new person * [arraysize];

When I intend to access a specific person do I have to do this? :

something = A->[i];

and when I want a specific object within my struct do I have to do this? :

something_else = A->[i]->random_int;

View 10 Replies View Related

C++ :: Pointer To Array Of Pointers

Feb 10, 2013

I'm just trying to get a handle on the uses of pointers here. Though clearly from my errors I'm missing a key concept. Here is my code: (You can assume that the array, "array_size" has values in it, I did this part in another function)

int main() {
bool **ptr_array;
int num;
int *array_size;
cin>>num;

[Code] ....

Once the program reaches the word[num] = false; some unhandled exceptions pop up.

I simplified my code a bit from my actual program and mixed up the loops, now the code should be in its correct form.

View 4 Replies View Related

C++ :: Pointers To Array Of Structs

Feb 14, 2013

I have an assignment where I need to use pointers to do a few things and I am a little confused on the syntax of it all. My question is how do you use a pointer to point to an array of structs.

For example

struct info{
char firstName[15];
char lastName[15];
};
main() {
info person[4];
cout << "The third letter of the second persons first name is: "; // ?????
}

how would I define a pointer to point to the third letter of first name the second person in the "person" array.

View 2 Replies View Related

C++ :: Array Of Pointers To Objects?

Dec 5, 2013

my code:

int OKCount=0;
int WaitingCount=0;
int ReservationCount=0;
Flight::Flight(int capacity, int waitingMax) {
seats=capacity;

[code].....

reservations is a data member in the class flight as:

Reservation **reservations;

OKReservation is a derived class and its abstract base class is Reservation.

My problem is that the reservations array loses its value in other function

View 8 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 :: Reading A File Into Array Of Pointers?

Mar 24, 2013

why when I print out "array[2]" nothing prints? It just prints blank space. My file definitely has text in it, but when I try to assign "text" into the array of pointers it won't show any text. I know fgets() appends a newline at the end of the string, not sure if that has anything to do with it, but I've tried printing everything that should be in "array" with a for loop and I get nothing.

Code:
#include <stdio.h>
#define FILEPATH "/home/user/Desktop/text"
int main(){
FILE *myFile = fopen(FILEPATH, "r");
if(myFile == NULL) return 0;
char text[100];
char *array[100];
int idx = 0;
while(fgets(text, 100, myFile)){
array[idx++] = text;
}
puts(array[2]);
}

View 2 Replies View Related

C :: Dynamic Array Of Pointers To String

Jun 11, 2013

I have a little problem with one of my functions. The function purpose is to get a number (n) and create an array (size n) with pointers to strings (each string length is 20 chars) and i don't know why but during the debugging i get a <bad ptr> message and this message :

CXX0030: Error: expression cannot be evaluated

This is my function:

Code:
char** getlist(int n) {
int i=0;
char **arr;
arr=(char**)malloc(sizeof(char)*n);
if (arr==NULL)

[Code] ....

View 8 Replies View Related

C :: Static Array Of Function Pointers

Jan 29, 2015

I basically have some code that lets users register callbacks into a callback table at a specified index. There is one element in this table for each event that can trigger a callback. I basically do something like this:

In a header file

Code:
typedef struct _GMclient
{
GMcommunicator gcomm;
GMclient_callback callback_table[(int)MAX_CALLBACKS];
}GMclient;

typedef int (*GMclient_callback)(GMclient*, void*, void*);

Then I allow them to set the callback with a function that basically ends up doing this (in a .c file that includes the previous mentioned .h file):

Code:
void
GMclient_register_callback(GMclient *client,
GMclient_callback fxn,
int index)

[Code] ....

Then later when I need to invoke that callback, I pull it out of the table

Code: GMclient_callback *fxn = client->callback_table[CMD_INDEX];

However, I get compilation errors:

Code: src/gmanager_client.c:43:6:

error: a label can only be part of a statement and a declaration is not a statement...

View 4 Replies View Related

C :: How To Pass 2 Array Pointers To A Function

Aug 4, 2013

How would I pass let say 2 array pointers to a function X , allocate memory for them in X , fill them with values and get them back in my main function without creating a structure.

example:

Code:

void X(int *a, int*b){
a= malloc ...
b = malloc ...
// fill a and b
return them back to the main function
}
void main(){

[Code]...

View 3 Replies View Related

C :: Basic Array Pointers Program

Feb 4, 2014

Code:

#include <stdio.h>
void Swap(int *x, int *y);
int *Largest(int *array, int size);
int main()
{
int a, b, i;
int c[10];
int maxaddress;
}

[code]...

My swap function works fine, but I am trying to find the ADDRESS of the largest element in my array and I am getting an error using gcc on my "return &largest;" and my printf line in my main function.How can I fix this and return the address of the largest?

View 8 Replies View Related

C :: Trying To Use Array Of Pointers To Alphabetize String

Dec 8, 2013

I am trying to alphabetize 3 different strings by comparing the first letter in each one. It will work for the first two names, but when I try to print out the third, I keep getting errors and I don't know why?

Code:
#include <stdio.h>
char personName();
int main() {

personName();
return 0;

[Code] ....

View 4 Replies View Related

C :: 3D Array Of Pointers To Linked Lists

Aug 8, 2013

I am having some trouble getting a 3d array of pointers to link up with a linked list for each of the array elements. the 3d array of pointers is declared like this:

Code:

struct particle *cell[MAXCELLS][MAXCELLS][MAXCELLS]; and there are linked lists declared like this:
Code: struct particle { /* structure for particles */
double sw[3]; /* square well components */
double hs[3]; /* hard sphere components */
double u[3]; /* unit vector for rotations */
struct particle *link;
};

I want to get the array pointers 'cell[x][y][z]' to point to the first observed particle in a function next to main, something like this:

Code:

void generate_list(){
int i,j,k,l;
/* determine the number of cells to decompose the simulation box in each of x, y and z directions*/
int(cells_x) = floor(boxX/cell_size);
int(cells_y) = floor(boxY/cell_size);
int(cells_z) = floor(boxZ/cell_size);
/* initialise the array of pointers to NULL */
for (j=0;j<cells_x;j++){

[Code]...

I am getting a pointer type cast error when I compile "assignment from incompatible pointer type",

View 6 Replies View Related

C :: Using Malloc For Array Of Character Pointers

Mar 30, 2013

I am able to work with n instances of a structure in one mallocated area, but when I try to do the same thing with just character pointers, I get compiler errors about making integer from pointer without a cast. If I create a structure with just a character pointer in it, it works just fine... I am just not seeing something here!!!

This works:

Code:
#include <stdio.h>
#include <stdlib.h>
int main (void) {
struct items {
unsigned int item_1;
unsigned int item_2;

[Code]...

This DOES NOT work!

Code:

#include <stdio.h>
#include <stdlib.h>
int main (void) {
char * items_ptr = NULL;
unsignedint i = 0;
char * one = "one";
char * two = "two";

[Code]...

View 9 Replies View Related

C++ :: Function Pointers Inside Array

Apr 6, 2014

Ive recently got into function pointers, i find that they can be quite handy for making your program very 'dynamic'.

However, the syntax is very confusing for what i want to do
This is what i want to do

I want to hold function pointers inside an array, but this array is dynamically allocated ( malloc, realloc, etc )

This is the current syntax ive come up with, but i dont think it is correct

void ( **drawFunc ) ( void*, SDL_Surface* );

View 2 Replies View Related







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