C++ :: Pointer (Save Address Value) To Char
Dec 9, 2013I have a pointer to an Address is there a way to save that address value (not the content but the actual address) into a char ?
View 5 RepliesI have a pointer to an Address is there a way to save that address value (not the content but the actual address) into a char ?
View 5 RepliesCode:
charArr = new char[50];
cout << "put in value: ";
cin.getline(charArr, 50);
some_func(charArr);
[Code] ....
Let's say I enter a value: 101
It goes into the if statement but clearly I've enter 1s and 0s. When I debugged, at i = 0, the charArr[i] gives me a value of 49 when assigned to an int variable. But when I cout charArr[i] it gives me 1.
So I'm going to assume 49 is part of the address? How can I correctly check the if statement condition?
lets say I have a char array with four elements but only one char is used, does it write four elements or just one?
View 3 Replies View Relatedchar num [] = pow(2,4);
how to save whole number to char array ? (16) so that menas char num [] = "16";
but it must be in this form :
char num [] = pow(2,4);
I've got a problem with a piece of code that it doesn't seem to work anymore.
Code:
#include <stdio.h>
#include <conio.h>
main () {
[Code] ..... i
I chose a to be 5 and it displays the following:
"Type a value for a:
5
5 in octal is: 5
5 in hexadecimal is: 5
Process returned 23 <0x17> execution time : 1.031 s".I first saw this when trying to display the address of a pointer. Am i missing something? I used to run this code on dev-c++ successfully but after a day or so of practice, it's not working anymore. I switched from dev-c++ to code blocks.
I am trying to use to save the current date and time into a char array using this code:
char current_time(char *date){
time_t result = time(NULL);
date = ctime(&result);
return *date;
}
main{
[Code]...
now when I output the date char array into a txt file I only get gibberish.
I have the following code.
StackElement *StackElementArray;
StackElementArray = new StackElement[iMaximumDepth];
I want to assign one element of this array StackElementArray the address of another object. For example,
voidStackMem::push(StackElement &iStackElement) {
CurrentDepth++;
StackElementArray[0] = iStackElement;
}
The StackElement class contains pointers to some dynamic arrays. When I use the assignment, StackElementArray[0] = iStackElement;, it doesn't copy the complete contents and I have to define an 'assignment operator' function to copy all the contents. I am wondering if there is a way I can assign StackElementArray[0] the pointer to the StackElement object. In that case, I will not need to copy the contents of iStackElement into StackElementArray[0] and will just copy the address.
What I'm trying to do is:
int *p;
someType memoryLocation;
cout<<"Enter your memory location: ";
cin >> memoryLocation;
p = memoryLocation;
cout << *p;
I was just messing around with some code, and was curious to if this was possible.
#include <iostream>
using namespace std;
void myfunc(int* ); // what do i put in these parameters to accept a mem loc of a pointer
int main () {
int x = 5;
[Code] .....
SOLUTION:
#include <iostream>
using namespace std;
//Purpose to create a function that returns a pointer to a pointer
int** myfunc(int**);
int main () {
int x = 5;
[Code] ....
Why my pointer skips over the colour addresses, it jumps to the next size address when I use Pointer++. I have tried changing the the char array to 4 bytes instead of 32 and whatnot but it doesn't work.
If I set the Pointer = the first colour address, it skips over the size addresses and only get the colour addresses. I know using 2 arrays would easily solve everything, but sadly I must use only 1.
I'll post whatever relevant code here:
For part of my program in class I have to take a pointer address and determine if it is equal to 0 modulus 16. But I can't figure it out.
View 1 Replies View RelatedI need to initialize a pointer variable with a knowing address. See code below, ptr is the final destination and value of ptr_address contains the address value, so I need to do something like ptr = *ptr_address.
Code:
int *ptr;
int *ptr_address;
int address;
address = 0x10000005;
ptr_address = &(address);
ptr = *ptr_address;
The problem is that compiler gives the following warning message:
warning: assignment makes pointer from integer without a cast [enabled by default]
Is my code wrong or there is any other way to do it without receiving this compiler warning?
Is there such thing as passing a winforms label by reference? For example, can I create a pointer label and pass the address to a function? I've looked online but couldn't find anything. Perhaps that's a sign?
View 1 Replies View RelatedI have an integer pointer and i want its address without allocating memory,
main() {
int *a;
cout<<a;
}
This is giving 00000000 and its but obvious. Now if i use address of a (&a) along with *a,
main() {
int *a;
cout<<a;
cout<<&a;
}
'cout<<a' gives me a constant address but 'cout<<&a' gives me different address.
what is the reason behind & and why behaviour of 'cout<<a' changes when using with &.
I want to store the address of a customer (with spaces) in a char variable (say cadd). First I tried to use "cin", as we know it reads until it sees any whitespace. So it reads only first word before a white space. So, I used "getline()" function, it will work. But when I used it, It did'nt wait for the I/P (it skipped it).
char cadd[20];
std::cout<<"Enter Customer Address:
";
std::cin>>cadd;
std::cout<<"Enter Customer Address:
";
std::cin.getline(cadd,20);
How can I add the variable adress to a void pointer inside of a class?
class variant2 {
private:
void *Vvariant=NULL;
public:
template<typename b>
variant & operator = (b *adress)
[Code] ....
if possible i want avoid the '&' when i assign the variable address.(variant2 f=varname;//like you see i don't use the '&')
for the moment i just need put the address to Variant pointer. but i receive several errors .
Sem is a pointer to semantic which is a struct type variable. I pass the sem into function yylex so i can fill the semantic.i and semantic.s(s points to an array). The problem is that when sem->i = a; is used inside yylex function, sem->s stops showing to the array.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <iostream>
using namespace std;
union SEMANTIC_INFO
[Code] ...
I'm having an issue coming up with an if() statement to check if a word match the one in the value of a pointer's address. So far the best I've come up with only matches the first letter of the words, you'll find it in the code below.
#include"Header.h"
int Colour(struct MyStruct *ArrayPointer, int ArraySize) //ArraySize = 3 for this run. {
int ColourCount = 0;
for (int i = 0; i < ArraySize; i++) {
[Code] ....
An example run you can see in attached pic.
I want to have an if statement that only accepts "Red" and not the occasional "Ravaged_Anus".
I'm using MVS Express 2013, .c source files, and the C++ compiler.
Attached image(s)
I'm attempting to save values from a char buffer into integer values of a struct.
This is what resides in the buffer "STD 2 2 2 2 2 2 2 " and this is my sscanf call
Code:
sscanf(buffer, "STD %d %d %d %d %d %d %d
", &dt_struct.date,
&dt_struct.mth,
&dt_struct.year,
&dt_struct.dow,
&dt_struct.hr,
&dt_struct.min,
&dt_struct.sec);
I then print the values back out in a string using sprintf.
Code:
sprintf(t_string, "STD %d %d %d %d %d %d %d
", dt_struct.date,
dt_struct.mth,
dt_struct.year,
dt_struct.dow,
dt_struct.hr,
dt_struct.min,
dt_struct.sec);
But this is what I get:
STD 0 0 2 0 0 0 2
Instead of what I want:
STD 2 2 2 2 2 2 2
I thought we needed to allocate memory before assigning a value to a char* and also that we needed to use functions like strcpy() to copy something into it. Then how come this works and does not crash?
Code:
#include <iostream>
using namespace std;
int main()
{
char * buf;
buf = "Hello";
cout << buf << endl;
buf = "World!!!!!!!!";
cout << buf << endl;
return 0;
}
I like to use a Pointer to char array. And then I would like to do a Pointer Arithmetic by incrementing the Pointer. Finally I would like to see the Addresses of the Pointer to each of the char Array Elements. I had created a program below, but I am not getting any Addresses from my Pointer.
#include <iostream>
using namespace std;
int main () {
int ArraySize;
char ch[]= "This is a Char Pointer";
char* iPtr = ch;
[Code] ....
#include <iostream>
using namespace std;
int replace(char *ptr, char c1, char c2);
int replace(char *ptr, char c1, char c2){
int count = 0;
int i = 0;
[Code] ......
Segmentation fault (core dumped)
I am trying to return a char pointer so that i can re use it again. I am writing a vigenere function that takes a message, a key and an initialization vector where it performs the encryption, prints out the encrypted message and returns the encrypted message. I print out the process step by step and everything works, however i pass the answer and print it out again and only the first letter gets changed. I put my code below and my output right after that.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
void decrypt(char *to_encrypt, char *key, char* pct);
enum flag{encryption = 1, decryption = 0};
[code].....
1st when i fill the things on form then saved in database after saving record when i want add another record it shows an error. after saving it saves new record refresh doesn't work
View 1 Replies View RelatedI am trying to develop a GUI using MFC, but I am having trouble using CFiledialog to save a file. The problem is, the file is not getting saved to the folder when I use the CFiledialog. Below is the code I am using.
Code:
CString szFilter = "XNRep Files (*.xnrep)|*.xnrep||";
CString s = "xnrep";
CString t = "";
CFileDialog fileDlg(FALSE, s, t, NULL, szFilter);
if(fileDlg.DoModal() == IDOK)
{
std::ofstream file;
[Code]....
After the file dialog opens up, I enter the name of the file and select OK button. But the file does not show up in the directory I am saving to.
Is there a more simple method to copy Buf into str? Buf is a binary string.
Code:
void function(string & str) {
int iWholeSize = 512;
char * Buf = new char[iWholeSize];
.... operations on Buf
string s(Buf, Buf + iWholeSize);
str = s;
}