In C (or C++ for that matter), pointers are special if they have the value zero: I am adviced to set pointers to zero after freeing their memory, because it means freeing the pointer again isn't dangerous; when I call malloc it returns a pointer with the value zero if it can't get me memory; I use if (p != 0) all the time to make sure passed…
I'm trying to free a character pointer after having used it but it returns a strange error.
The error says: "_CrtDbgREport: String too long or IO Error"
The debugger itself returns no errors while compiling.
The code currently looks like this:
void RespondToUser(SOCKET client, SOCKET server)
{
char buffer[80];
char *temp =…
I radically re-edited the question to explain better my application, as the xample I made up wasn't correct in many ways as you pointed out:
I have one pointer to char and I want to copy it to another pointer and then add a NULL character at the end (in my real application, the first string is a const, so I cannot jsut modify it,…
This should be super simple, but I'm not sure why the compiler is complaining here.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int *n = 5;
printf ("n: %d", *n);
exit(0);
}
Getting the following complaints:
foo.c: In function ‘main’:
foo.c:6:
warning: initialization…
Hello,
Hopefully my title was descriptive enough to attract the right help.
I want to write a function that will return 1 thing, and modify a provided pointer in another.
My current function declaration is . . .
char * afterURL replaceURLS(char * body)
What I want to do is copy all of body's data into a new string, and…
could someone explain to me why the following results in a Null pointer Exception? And how to set a value for bitarray[0]?
BitSet[] bitarray;
bitarray= new BitSet[10];
bitarray[0].set(1);
Also, why something like this work and not result in a pointer exception?
BitSet[] bitarray = new BitSet[10];
…
I want to refer a pointer to an array by another pointer.
Example:
void exp()
{
double var[2];
exp1(&var[0]);
printf("\n varvalue is %lf\n",var[0]);
}
void exp1(double *var)
{
//updating the value
*var[0]=4.0;
exp2(&var[0]);
}
void exp2(double *var)
{
*var[0]=7.0;
}
This should update the value as 7.0(the last…
Ok, to begin with, this is my code:
HyperSprite::HyperSprite()
{
_view = 0;
}
void HyperSprite::publish(QGraphicsView* view) {
_view = view;
}
void HyperSprite::getKFrame() {
if(_view != 0) {
qDebug()<<(void*)_view;
}
}
Now, if I call HyperSprite::getKFrame() from within main(), I get the…
Everytime I look at a C function pointer, my eyes glaze over. I can't read them.
From here, here are 2 examples of function pointer TYPEDEFS:
typedef int (*AddFunc)(int,int);
typedef void (*FunctionFunc)();
Now I'm used to something like:
typedef vector<int> VectorOfInts ;
Which I read as
typedef…
How many methods/ways are there taking input by using with pointer and dynamic memory?
Input:
3 1 2 n k l 2 1 2 p 4 55 62 * # x
(x is stop value, first input always integer)
Example code:
p=malloc(sizeof(int));
scanf("%d",&num_arrays);
while(1)
{
scanf("%c",&(*(p+i)));
if(*(p+i)=='x')
…
I am trying to convert a void pointer to an array of classes in a callback function that only supports a void pointer as a means of passing paramaters to the callback.
class person
{
std::string name, age;
};
void callback (void *val)
{
for (int i = 0; i < 9; i++)
{
std::cout <<…
I am completely new in c++ programming. I want to copy the array called distances into where pointer is pointing to and then I want to print out the resul to see if it is worked or not.
this is what I have done:
int distances[4][6]={{1,0,0,0,1,0},{1,1,0,0,1,1},{1,0,0,0,0,0},{1,1,0,1,0,0}};
int *ptr;
ptr =…
Suppose there are Base class and Derived class.
Base *A = new Base;
Here A is a pointer point to Base class, and new constructs one that A points to.
I also saw
Base *B = new Derived;
How to explain this?
B is a pointer to Base Class, and a Derived class constructed and pointed by B?
If there is a…
input
23 3 4 4 42 n 23 0 9 9 n n n 3 9 9 x
//according to input,i should create int pointer arrays. pointer arrays
// starting from 1 (that is initial arrays is arrays[1].when program sees n ,it
// must be jumb to arrays 2
// the first int input 23 is num_arrays which used in…
I have the following program for books record and I want to sort the records on name of book. the code isn't showing any error but it's not sorting all the records.
#include "stdio.h"
#include "string.h"
#define SIZE 5
struct books{ //define struct
…
There are several screen capture tool questions already on this site, but I think I have a slight tweak to the usual. I'd like a handy screen capture utility that can:
Run in Windows 7
Capture a sub-region of the screen
Show the current state of the mouse cursor and any active menus
I'd like…
I just got an HP 2710p (hp tablet, with digitizer), and I've played around with linux for a while now, and thought I would go ahead and install it. Everything works fine, excepting normal tablet functions, which is to be expected. I'm working on the screen rotation, and there are on-screen…
I only see black screen after the startup. It just shows the logo and the status bar upon start, then it goes black screen with moveable cursor. I tried alt+ctrl+del, but it doesn't work. I pressed shift 5 times and it makes a sound. I already removed battery and restarted it, but still…
I only see black screen after the startup. It just shows the logo and the status bar upon start, then it goes black screen with moveable cursor. I tried alt+ctrl+del, but it doesn't work. I pressed shift 5 times and it makes a sound. I already removed battery and restarted it, but still…
We have a SBS2003 server that was migrated to a new hardware platform, the computer name has changed but the domain is the same. The desktop's are trying to do offline files to the old server name. There is a nslookup entry for the old server name and a DNS entry for the old server.
…
I need straight paths with end markers for associating text to parts of the image.
For better readability, it needs to be high-contrast, i.e. a white line with black outline.
Stroke to path will create a group of a box and a circle from the line with end marker.
This makes placement…
Hey,
I'm working on a small roguelike game, and for any object/"thing" that is not a part of the map is based off an XEntity class. There are several classes that depend on it, such as XPlayer, XItem, and XMonster.
My problem is, that I want to convert a pointer from XEntity to…
I am trying get a handle on C as I work my way thru Jim Trevor's "Cyclone: A safe dialect of C" for a PL class. Trevor and his co-authors are trying to make a safe version of C, so they eliminate uninitialized pointers in their language. Googling around a bit on uninitialized…