174 Topics
|
|
Hi, This is probably, a really novice question, but I have some code that is using the malloc() function to declare an array, the problem is that I am using a special compiler to compile code for hardware which gives me a lot of errors because of the stdlib.h header … |
|
[CODE] #include<iostream> #include<cstring> using namespace std; class city { protected: char *name; int len; public: void getname(void) { char *s; s= new char[30]; cout<<"Enter city name: "; cin>>s; len= strlen(s); name= new char[len+1]; strcpy(name,s); } void printname() { cout<<name<<"\n"; } }; int main() { city *cptr[10]; int n=1; int option; … |
|
HEllo this is reaaally urgent, the deadline is within less than an hour and thirty minute, and I lost hope that I can fix the problem myself. I know it has to do with pointers and allocating memory dynamically. The assignment was to use operator overloading to add two sets … |
|
I am trying to write a program that dynamically increase the size of an array. essentially creating an array inside of an array with array [b]a[/b] storing 100 int pointers. my code is initially having problems on line [code] a[count] = new int [n]; [/code] any tips or pointers as … |
|
Can anyone help me with searching for a particular address in a given range in C. like i have to search for *ptr in range specified by *high and *low. i think it is not same as linear search. can someone provide some input. thanks. |
|
Been working on this for 2 hours non stop. Can't seem to figure out exactly what's the problem. Perhaps I'm taking a wrong approach to this problem. Right, I need to copy a singly linked list to another new list. Can use any method EXCEPT RECURSION. Here's the code so … |
|
I'm having problems with the code from my text book. I need modify the class so it throws an exception instead. The problem is that I get errors from the original code from the book. Any help on how to fix it would be great. Thanks in advance! ERROR: [COLOR="Green"]Error … |
|
Yeah this is a simple question and pretty popular. And this is what I did. There is a segmentation fault when we copy characters from [ICODE]src [/ICODE]into [ICODE]dest[/ICODE]. Now, I can understand the source of this fault - when we iterate over the [ICODE]dest [/ICODE]string we reach the end and … |
|
hey guys! mind if you help me here? we were asked to make a grading system. here is my code.. [CODE] #include <iostream> #include <string> #include <cstdlib> #include <iomanip> using namespace std; void main() { system("CLS"); char fn[50],ln[50]; string *name, *enam, temp, *R, wN, fin, lan; double gr, *g, temp2, … |
|
[B]Specifications (minimum):[/B] The CDROM class contains the following, private, data members: string Name; // The Name of the CDROM string CDType; // The Type of CDROM float Cost; // The Cost of the CDROM [I]The ONLY recognized (i.e., legal) CDROM types are, “Game”, “Word”, “Compiler”, “Spreadsheet”, “Dbase”, and “Presentation” (AND, … |
|
I've searched all over google and this site. I've found a few hints here and there but after i make the changes either my compiler throws a fit or it doesn't produce the desired results. Here's what i want: I want to create a linked list in the main function … |
|
[code] class Node { private: int integer; Node *pointer; public: Node(int x = 0, Node *y = NULL) { integer = x; pointer = y; } int getInteger() { return integer; } Node getPointer() { return *pointer; } }; [/code] [code] private: Node *stack; Node *top; int listSize; int pushedValue; … |
|
Hi there, Can anyone tell me why variables can have printed values of -858993460. I've got a pointer pointing to a memory address which has nothing in it so when i come to cout this it prints -858993460, if i give it a value then its prints that value. I … |
|
[CODE] #include <stdio.h> #include <string.h> typedef struct { char firstName[50]; char lastName[50]; int age; }Person; void ModifyPerson(Person*); int main() { Person person; strcpy(person.firstName, "firstName"); strcpy(person.lastName, "lastName"); ModifyPerson(&person); printf("First Name=%s\nLast Name=%s\n",person.firstName, person.lastName); system("PAUSE"); } void ModifyPerson(Person *p1) { //This doesn't modify the original variable declared in main function Person person = … |
|
Hi, there i didn't even know is that how its called but can you help me and tell me what is that LLIST from the structure into the type function and why its used in this case: [code=c] typedef struct node { int data; struct node *next; /* pointer to … |
|
I'm getting a segmentation fault when I try to search a linkedlist using the following description: [CODE] //! Searches for the first occurrence of value v that appears in the list //! after node n //! //! @param v The value being searched for //! @param n The node in … |
|
This is my first post here on Daniweb and I intend to do things right. I actually did read the "READ THIS FIRST" thread and instead of posting 500 lines of code I whipped up a test program I aptly titled test.cpp First I will walk you through my problem. … |
|
Hello again. For the current lab, we're working with strings and pointers. I'm trying to keep this one simple and get one step working right before I move on to the next. However, if I have subsequent issues with this lab, I'll just use this same thread rather and make … |
|
I was having some confusions about string and NULLs. So, I read this [URL="http://www.daniweb.com/forums/thread77987.html"]thread[/URL] on this very forum. But, I could not understand somethings... Firstly, Is NULL an integer value 0, or something else? Secondly, [CODE]if(strlen(str)==0)[/CODE] this shows that the string is null or it shows that the first character … |
|
SortedInsert() is a function which given a list that is sorted in increasing order, and a single node, inserts the node into the correct sorted position in the list.I know this code works fine.I am just curious to know why we can't use just single pointer to node to traverse … |
|
Hey guys I'm having a little problem with unsigned char and reading a file of integers into the array. 1. What the program is suppose to do: It's suppose to dynamically create an array of unsigned char that is the correct size to read in the array of numbers. The … |
|
Hi all, I have a more philosophical question which I think might help me to better understand the interest of pointers in C++. Indeed, my background is mainly Perl and a bit of Java. I am currently implementing (as an exercise and because I work in this field) a class … |
|
Hi, well what I'm trying to do with this, is to read a text file line by line and pass its data to the struct. the problem is that not only i can't read the strings and put it on the struct fields, I also get a segmentation fault. Could … |
|
I am facing some problems trying to understand the difference in handling strings when they are declared as a char array and when they are declared with a pointer pointing to them. In the following code snippets, I have a few doubts. 1.While code 1 works correctly, code 2 crashes … |
|
Hi, I believe this is my first posting to DaniWeb, so thanks very much in advance for your time! I have been doing some searching and I am not sure of a definitive answer to the following problem. I am attempting to make a class that can store a set … |
|
Hey guys, What I'm trying to do is a function that gets a certain array of structures and print some of the information on the screen, like the name and id_number. The thing is that some fields in the structure are repeated and my goal is to show only one … |
|
|
Hello. I am writing a program with some dynamic arrays of pointers to objects (not arrays of objects). Since there will be A LOT of tacking on new objects to the arrays, for the purposes of efficiency, I am implementing an algorithm to fill up a buffer array first and … |
hi guys, I'm trying to implement a basic program which deals with structures and pointers. I have to insert data for various citizens, which is structure that have other structures as fields. in this case my main objective is to create 2 general functions that will get the information for … |
|
Hello, I am currently trying to write a board game, and I am having trouble making each GameTile on the board access the same Point on the board. Each GameTile contains a certain number of Points, and sometimes Points overlap(the Point on a corner of one tile may be the … |
The End.