54 Solved Topics

Remove Filter
Member Avatar for
Member Avatar for catastrophe2

the following short program asks user to enter # of hospital rooms (between 1-5), and asks for number of flowers, which cannot be a negative number. Then, it picks based on how many rooms the price from the `hospitalRoomsPrices_Array[5]`, and it also displays the total flowers multiplied by $2.50 each. …

Member Avatar for Reverend Jim
0
302
Member Avatar for nitin1

Hi, I am facing an issue in string to const char pointer conversion. I am doing stuff in the fun() but here i am just giving my example. Here it the code: // Helper function string fun() { string abc = "Daniweb"; // print here #1 return abc; } // …

Member Avatar for AssertNull
0
3K
Member Avatar for rvndrdahiya

I declared two different char * and initialised them to the same string. but i thought they would be pointing to the different addresses , but they pointed to the same addresses.. How come this happens? char* arr = "abcdefgh"; char* brr = "abcdefgh"; cout<<arr<<endl; cout<<brr<<endl; the values printed out …

Member Avatar for rvndrdahiya
0
279
Member Avatar for kent.johnstone_1

I need some pointers with pointers. What is the difference between a variable preceded by an "*" and an "&"? Some of my sample code uses one and some the other. I'm getting compiler errors trying both saying the variable is not defined. First use this function.

Member Avatar for kent.johnstone_1
0
417
Member Avatar for tanatos.daniel

I have an abstract class CArticle and two derived classes CBook and CMagazine. I also have a class CLibrary where i want to add articles. Its members are an int variable to count the articles and a double pointer of CArticle. I have the following main function: int main() { …

Member Avatar for tanatos.daniel
0
447
Member Avatar for eldiablo1121

Hello, First of all I want to thank all the help with my posts. I have a program where I have to convert a phrase from lower case to upper case, but I cannot use any of the toupper() isupper() functions and vice versa. I think I almost got it, …

Member Avatar for eldiablo1121
0
2K
Member Avatar for eldiablo1121

Hello, I have a program assignment that I have no idea what it's asking for honestly. I've tried to read all I can about it, but I do not understand. I tried my hand at some code, but it's only returning the address of course. Here is my attempted code: …

Member Avatar for eldiablo1121
0
417
Member Avatar for saurabh.mehta.33234

I have the following code.According to this the values of pointers p[0] and p[1] remains unchanged since the swap is made to local variables in swap function.Now my doubt is how can I swap the pointers p[0] and p[1] inside the function swap?? #include<stdio.h> int main() { char *p[2]={"hello","good morning"}; …

Member Avatar for Schol-R-LEA
-1
196
Member Avatar for FelineHazard

Hi guys What's the default pointer value in c++? Can I count on the compiler to set an uninitialized pointer to NULL? Is it compiler dependant? What's the "consensus"? Thanks! -FH

Member Avatar for FelineHazard
0
693
Member Avatar for phfilly

Hi I have trouble with implementing a dynamic two dimensional pointer array on allocating memory for it. I tried it this way but not sure if it's correct. The array should contain pointers to heap allocated **Integer** objects const int size = 10; Integer *** twoD; twoD = new Integer**(); …

Member Avatar for Ancient Dragon
0
321
Member Avatar for davecoventry

I am studying the C++ code from an opensource project (libredwg) I have the following code: `*offset = *(*src)++;` What does this do? I understand offset = *src++; which would assign src[0] to the variable 'offset' and then increment src so that it points to what was previously src[1].

Member Avatar for davecoventry
0
138
Member Avatar for Alexkid

Hi there I have a question about pointers, i have a functions that takes a path to a txt file, extracts whats in it into an array and returns the array. As i understand it you can't actually pass the array, you have to return the pointer to the array …

Member Avatar for Alexkid
0
254
Member Avatar for Lord_Migit

Hi there. I am having some trouble trying to figure out how to delete a pointer that is held in a vector. int main() { vector<Test*> iVector1; vector<Test*> iVector2; vector<Test*>* pVec1(&iVector1); vector<Test*>* pVec2(&iVector2); pVec1->push_back(new Test(11)); pVec1->push_back(new Test(12)); pVec2->push_back(new Test(23)); pVec2->push_back(new Test(24)); //delete iVector1.at(0); delete iVector1[0]; iVector1.at(0) = new Test(21); pVec1->at(1) …

Member Avatar for Lord_Migit
0
248
Member Avatar for bgx90

I have not found anything that addresses these questions. Any help is appreciated. If I have a class that has pointers to objects of a user-defined class as members, is there any problem with initializing those pointers with the initialization list of the constructor? For example, where A, B, and …

Member Avatar for bgx90
0
3K
Member Avatar for TreeBranches

My program begins by opening a dictionary file, the first line of which contains the number of words in the dictionary. If I print the words immediately after scanning them into the arrays, they appear fine, but if I later examine a previous entry, I can see it has been …

Member Avatar for TreeBranches
0
207
Member Avatar for ineedsomehelp:3

[CODE]void alternate(char wordWord[][MAX],char wordVar[],int word[],int i,int j, int k, int l) { char ang[4],si[3],ni[3],ay[3],sa[3],kay[4]; int X,Y,Z1,Z2; strcpy(ang,"ang"); strcpy(si,"si"); strcpy(ni,"ni"); strcpy(ay,"ay"); strcpy(sa,"sa"); strcpy(kay,"kay"); tokenize(wordWord,wordVar,word,i,j,k,l); if(wordWord[j][k] == ang[4] || wordWord[j][k] == si[3]) X = wordWord[j][k]; else if(wordWord[j][k] == ni[3]) Z1 = wordWord[j][k]; else if(wordWord[j][k] == ay[3]) Y= wordWord[j][k]; else if(wordWord[j][k] == sa[3] …

Member Avatar for ineedsomehelp:3
0
329
Member Avatar for thache

I've been trying to figure out whats wrong here, but I just can't wrap my head around it. My compiler outputs the following when I attempt to compile it. [CODE] z:\Desktop\tmp\proj4>cl proj4_linkedlist.c Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. proj4_linkedlist.c …

Member Avatar for thache
0
339
Member Avatar for shuchi0113

int main(){ int near * ptr=( int *)0XFFFF; ptr++; ptr++; printf(“%p”,ptr); return 0; } Output:0003 why the op is 3 and how to convert 0XFFFF into its decimal equivalent?

Member Avatar for shuchi0113
0
581
Member Avatar for freedomflyer

I am trying to pass some url information into tokenize_urls from process_and_display_information. To get things up and running, I am simply trying to return and retain some array data from tokenize_urls into process_and_display information. However, I am running into an issue where the variables are created and sent back from …

Member Avatar for Ancient Dragon
0
171
Member Avatar for hamby

Hello daniweb, I've been having problems with a program I'm trying to make, in my function definitions, I'm trying to reference the output of one function in the other's definition, but not sure how to, I'm guessing pointers could help me but I'm not sure how to use them: These …

Member Avatar for Moschops
0
154
Member Avatar for bennetk2

I am having problem with converting and initializing errors. Any help is appreciated. I am a 2 yr Computer Science major, so be gentle. Here is Code: Sorry its long! [CODE]// Kyle Bennett // CS 318 // Paint Throwing Disturbance #include <iostream> #include <iomanip> // set width and decimal #include …

Member Avatar for raptr_dflo
0
359
Member Avatar for eviandc

Hi, I'm a beginning C++ student and have an assignment to dynamically create an array of a struct to store students' first names, last names, and test grade scores, and then pass it via pointer to a function that will sort the grades and names in ascending order. I wrote …

Member Avatar for eviandc
0
1K
Member Avatar for king03

Can someone please explain to me how the pointers were used in the line w/ the red font. I do not understand where the pointer pertains to and why there is still a need for that. Also why is it that a "+" sign was used to combine two array …

Member Avatar for Ancient Dragon
0
133
Member Avatar for kangkan_14

Here is a part of code I am writing.I am getting a segfault in the CmpFunc function. The segfault occurs when I compare *a and *b i.e in the "if(*a>*b)" line. I am new to function pointers. So, I might be making a mistake somewhere which I don't realize.I would …

Member Avatar for kangkan_14
0
2K
Member Avatar for termin8tor

Hey all, I'm attempting to use an STL List to store a list of objects. Now I realise it's quite trivial to store a list of objects of my own definition. My real question is, how do I fill the list with objects that inherit from a base class. E.g. …

Member Avatar for termin8tor
0
267
Member Avatar for sajay

Hello I'm coding an algorithm based on genetic programming with tree structures in C. I implemented tree structure using recursive structure pointers **The traditional way** [CODE] struct tree { int val; tree *left; tree *right; }; tree a[10]; tree b[20]; void main() { generate (); // this generates me 10 …

Member Avatar for sajay
0
186
Member Avatar for bensewards

Hey everyone, I have to manipulate two functions RECURSIVELY, strlen and strcpy. I was able to code the strlen: [CODE]int length(char* str){ if(str == NULL){ return 0; }else{ return length(str, 0); } } int length(char* str, int l){ int len=0; if(str[l]){ len = length(str,l+1); } else { return l; } …

Member Avatar for bensewards
0
746
Member Avatar for globberbob

Hey there, working on a program thats going to have a bunch of functions, but for now I am stuck on something that will be reused throughout the program alot: passing a string pointer to a function. It may seem redundant or arbitrary that I am passing it as a …

Member Avatar for globberbob
0
7K
Member Avatar for Buffalo101

Hello, This is an extension of this thread: [url]http://www.daniweb.com/software-development/c/threads/357681/1525001#post1525001[/url] My purpose is to create a class that handles a network message. Irrelevant, anyway. CMyMessage: [code=C] #include "stdafx.h" #pragma once #include <conio.h> #include <stdio.h> #include <iostream> #pragma once using namespace std; typedef unsigned char byte; class CMyMessage { protected: byte type; …

Member Avatar for Buffalo101
0
682
Member Avatar for dooleyis

Hi everyone, I was wondering if it is possible to point to a textbox created in the form designer via a string variable. Basically, I'm creating a golf management system with a feature allowing a user to define their own course. Each hole has a corresponding textbox into which a …

Member Avatar for dooleyis
0
210

The End.