C :: Setting Values To Pointers
Apr 5, 2014
This function below takes a pointer as an argument. What I expect to happen is, since expr++ has higher precedence than *expr, that is, the primary expression operators have higher precedence than the unary operators, pointer arithmetic should occur where we increment to the second address pointed to by dbuf, and then we should dereference the value at that address. Given that logiv, when i print dbuf[3] it should print the value pointed to at the 4th address in dbuf. However, the value it returns is 0x0 not 0x3. Why doesn't it dereference the value 0x3?
Code: void dfill(unsigned char *dbuf)
{
dbuf = (unsigned char*)malloc(4);
memset(dbuf, 0, 4);
*dbuf = 0x0;
*dbuf++ = 0x1;
*dbuf++ = 0x2;
*dbuf++ = 0x3;
printf("dbuf val: 0x%x
", dbuf[3]);
}
View 1 Replies
ADVERTISEMENT
Dec 18, 2013
How do I set all of these string and double value(s) to 0?
Code:
#define MAXcharacters 12
#define MAXaccounts 100
struct Records {
char userid[MAXcharacters + 1];
char password[MAXcharacters + 1];
double balance;
};
[code]...
View 3 Replies
View Related
May 19, 2014
in the following code how would i set a txt file up to where i can have say name = whatever in it and the program will find it and set it to the corresponding global value.
#include <fstream>
#include <iostream>
#include <string>
[Code]....
View 1 Replies
View Related
May 21, 2012
I'm wanting to create an image, all I need is to be able to set RGB values and X-Y coordinates, I'm not wanting to read or manipulate images. Any easy to use library or another simple method of doing this?
View 1 Replies
View Related
Sep 9, 2013
The problem may only apply to VC++ compiler - ??.
Cannot do this:
const unsigned int Port = 0x900E0000;
unsigned int *pData = Port; //Error - can't convert from int to int*.
Solution:
const unsigned int PORT = 0x900E0000;
const unsigned int PORT_PTR = ((unsigned int *)0x900E0000);
unsigned int *pData = PORT_PTR; //No Error.
I found no way to do it but the above.
Ex., you cannot do:
pData = (unsigned int *)0x900E0000;
View 1 Replies
View Related
Aug 31, 2014
What is the difference between initializing pointers to a memory address using the address operator like int *pointer = &x; or initializing it to a value like int *pointer = x; .. in other words how does p and q point to the same memory address in:
const int ARRAY_LEN = 100;
int arr [ ARRAY_LEN ];
int *p = arr;
int *q = &arr[0];
View 4 Replies
View Related
Apr 20, 2014
I'd like to do a MergeSort with sentinels and order the pointers, not the values!
#include <iostream>
#include <limits>
using namespace std;
void
stampa (int *n) {
int i;
for (i = 0; i < 10; i++) {
[Code] .....
View 9 Replies
View Related
Sep 26, 2014
typedef struct example_dt_struct {
int a;
float b;
char* c;
};
typedef void(*func)(example_dt_struct *s, int e, int f);
void f(func *n){}
how can i use example_dt_structure with my function pointer into f()
View 5 Replies
View Related
Apr 26, 2012
My project is say that it has memory leaks. When I view it in the debugger, it shows the correct values being passed to the pointers.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
bool ConfigGetEntry( char *pcFile, char *pcNameMust, char* &pcResult ) {
char pcBuffer[ 512 ];
[Code] ....
Its saying that i have memory corrupting at..
Code:
if ( !ConfigGetEntry( pcFile, pcName, pcRet ) ) return _strdup( pcDefault );
Also is it normal to have a bad pointer then point data into it to then clear that of the bad pointer. To have valid data now in that pointer.
View 3 Replies
View Related
Feb 28, 2014
Which is more efficient in functions? Returning values or using pointers to redefine variables passed as arguments?
I mean either using:
void ptr_Func(int *x)
{
*x = *x+1
}
or
int ptr_Func(int x)
{
return x + 1;
}
In terms of speed, memory use etc.I want to know general efficiency, I know it will obviously vary with different uses and circumstances.
View 7 Replies
View Related
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
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
Mar 1, 2013
Lets say i have an array with the values 1, 5, 9, and 3. is there anyway to make this so i can have an int with the value 1593 based on those numbers in the array?
View 8 Replies
View Related
Feb 22, 2013
I want to set limit on cin for example
int i;
cout<<"Please enter 4 digits id: ";
cin>>i
If user enter more then 4 digits it must give an error
View 5 Replies
View Related
Oct 18, 2013
I am trying to create the lparam for the WM_KEYDOWN message. I know this is the C programming forum, but my code is standard enough to apply here. According to Microsoft, the lparam must be formatted like this : lParam The repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown following. Bits Meaning 0-15 The repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent.
However, the repeat count is not cumulative. 16-23 The scan code. The value depends on the OEM. 24 Indicates whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0. 25-28 Reserved; do not use. 29 The context code. The value is always 0 for a WM_KEYDOWN message. 30 The previous key state.
The value is 1 if the key is down before the message is sent, or it is zero if the key is up. 31 The transition state. The value is always 0 for a WM_KEYDOWN message. ( WM_KEYDOWN message (Windows) )^ I'm troubled by setting it into the 32-bit value, and I get confused about what exactly happens when the logical or and the bitshift operators are used. I tried to use them below in my code by looking at Stack Overflow for setting a bit. I also don't know how to test for the endianess of my system, and how to handle it if it's big endian or little endian. Here is my code so far :
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
[Code].....
View 2 Replies
View Related
Oct 27, 2013
I have the following situation:
Code:
void myFun(float *pfMyPtr) {
float Val[] = {0.234, 0,432, 0.322, 0762, 0.984};
pfMyPtr = Val;
}
int main() {
float *pfPtr;
pfPtr = (float*) calloc (5,sizeof(float));
myFun(pfPtr);
}
I would like pfPtr to contain the values of array Val. What am I missing here?
View 5 Replies
View Related
Oct 29, 2014
I need to set a function to a variable of some kind. Then later in the program it needs to run the function that is set to the variable. The variable doesn't need to change after it is set to a function, it just needs to be able to be set to a function. So maybe I don't need a variable? What do I do? :3 Is this even possible? :o
Example:
if (PosRampYes == 0)
{
SomeVariableOrSomething = FirstFunction();
}
else
{
SomeVariableOrSomething = SecondFunction();
}
//later:
SomeVariableOrSomething; //so if PosRampYes is set to 0 then this line would run FirstFunction()
View 2 Replies
View Related
Oct 8, 2013
I am trying to find a quicker way of setting the variables for text. here is my code:
sf::Text set_text_values(sf::Text text, sf::Font font) {
text.setFont(font);
text.setCharacterSize(50);
text.setColor(sf::Color::White);
return text;
[Code] ....
And I have tried it like this
void set_text_values(sf::Text text, sf::Font font) {
text.setFont(font);
text.setCharacterSize(50);
text.setColor(sf::Color::White);
[Code] ....
The code compiles and runs but it won't show the text on the screen like it did when i did it manually like this:
int main() {
Hull.setFont(font);
Hull.setCharacterSize(50);
Hull.setColor(sf::Color::White);
}
What is wrong with it?
View 2 Replies
View Related
Sep 18, 2013
I'm trying to set all the elements of my array to 0 but nothing seems to be working.
.h
#ifndef ServerGroup_h
#define ServerGroup_h
class ServerGroup {
public:
ServerGroup(const int&);
[Code] .....
I want to set each element of the array in servers to 0 based on what is passed into size by numArray.
View 9 Replies
View Related
Feb 20, 2013
I declared a pointer in main with value 0, so I want to change its value so that it points to other variable from a function, I guess the function creates a copy of my pointer that's why whatever I do within function doesn't change the real direction of the pointer in main. I've been trying something like this:
#include <stdio.h>
void redirectionate(char *str, char *ptrCopy);
int main()
{
[Code]....
View 7 Replies
View Related
Apr 3, 2015
I would like to know how can i set a constant attribute in the constructor. This attribute is an int value that cannot be changed.
For instance:
class Test {
public:
const int x;
public:
Test(const int val);
[code].....
With this code i get compile error!
View 5 Replies
View Related
Jun 23, 2014
I created a WinForm app in C# using VS 2013 Express.
I added code to create a Global Hot Key on the main form. This works fine. My hot key is Ctrl-T. I can press the hot key and make the main form show and hide.
Then I created a second form (ChecklistForm) and now I want to press ctrl-T and make that form show and hide. I do not need the main form to do this any more. I just used the main form to test my Global Hot Key code.
So I'm having trouble getting the second form to respond to the hot key. When I put a break on the WndProc(), there is no break.
namespace ChecklistFSX {
public partial class MainForm : Form {
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String sClassName, String AppName);
private IntPtr thisWindow;
private GlobalHotKeys hotkey;
public MainForm()
[code]....
View 2 Replies
View Related
Feb 7, 2013
Basically the whole purpose of this program is to prompt the user to use a calculator. Choices 1-6 are valid, but I want to set it up where selecting any other number outside of 1-6 to be Invalid, and will display an 'Invalid Choice' message, and then go back to the main menu.... The main program does work properly, it's the 'Invalid' setup that is giving me problems
Code:
#include <iostream>
#include <iomanip>
using namespace std;
[Code].....
View 10 Replies
View Related
Aug 12, 2013
I am having trouble setting up SFML 2.1 to run with the eclipse IDE for c++ development. I use MinGW for my compiler.
When I link my include folder, lib folder and dll's it will not run a simple SFML program.
View 2 Replies
View Related
Mar 29, 2015
Just reading some code and come across a section where its setting the resolution on a screen
so like
image->sizeX=640;
image->sizeY = 480;
size = image->sizeX * image->sizeY *3;
float sizeLog = ceil(log((float)image->sizeX) / log(2.F)));
So yea, my understanding of this code is that firstly there is member access and that a resolution is being set.
And then its like 640 * 480 * 3
and then the log of 640 *480*3 ...being divided by something else and being rounded up by ceil
is this the right way to look at it?
and also what is the log(2.F) - i don't really understand that.
View 3 Replies
View Related
Jun 27, 2013
I am trying to find out when using float in a calculation how to set the number of decimal places. For example my code below
Code:
#include stdio.h>
int main()
{
float x=123.0;
[Code]....
This returns an answer 8487.0000 I would like it not to show all the decimal places. However if the sum has decimal places I would like to select the number of decimal places shown.
View 3 Replies
View Related