Questions tagged [char-pointer]

Character Pointer is a data type which holds the address of a primitive charter type variable.

Character pointer can point to a memory address which holds a character value in the form of ASCII Code. A static character array also decays into a char pointer. A Char pointer can be allocated memory dynamically using this syntax.

char *char_ptr = new char ;

It can also be allocated a whole char array and it points to the first index of that dynamic array.

char *char_ptr = new char [10] ;

Typically, as with other pointers, a char pointer takes 4 bytes of memory in the system. Its properties match those of other pointer types with slightly different behavior. The compound operation of assignment and output are allowed on char pointer. If a char pointer points to a cstring, these operations are possible on it which are not legal on any other pointer type.

char *char_ptr = "hello world" ;
cout << *char_ptr ;
171 questions
0
votes
1 answer

returned pointer address getting modified when ASLR turned on

I have this piece of C code running on development box with ASLR enabled. It is returning a char pointer (char *) to a function, but somehow few bytes in the returned pointer address are getting changed, printf output below: kerb_selftkt_cache is…
new_c_user
  • 123
  • 2
  • 12
0
votes
1 answer

Attempted to read or write protected memory : C++ Modified Value of Memory

I for trim string "char array in c and c++ or char pointer" use this function: inline char * trimRight(char * str) { char * end = str + strlen(str); while(str != end) { end--; switch(*end) { case ' ': …
evergreen
  • 7,771
  • 2
  • 17
  • 25
0
votes
2 answers

Pass a string Recursively without Recreation

I answered a question here: https://stackoverflow.com/a/28862668/2642059 Where I needed to use recurrence to step through a string. I wanted to use a const string& as my parameter on each function, but unless I wanted to reconstruct the string each…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
0
votes
1 answer

Basic C cast warning pointer from int

Can someone tell me how to correct this warning/error. I am trying to get just the first character of a string to tell if it a "-". Error: grep-lite.c:15:13: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] …
napkinsterror
  • 1,915
  • 4
  • 18
  • 27
0
votes
2 answers

Unitialized Heap Allocation Misunderstanding (Code Works -- Need to Correct to Remove Valgrind Error)

My code works fine, but I am receiving valgrind errors. I want to know how to correct my code to in respect to using these malloc and free statements correctly with the char * * dest. Please don't tell me not to malloc and free unless I am doing it…
napkinsterror
  • 1,915
  • 4
  • 18
  • 27
0
votes
2 answers

Cast a vector of std::string to char***

I have an API function that expects a char*** parameter and want to pass a vector. Are there member functions of std::string that let me do that? This way, I only get the char pointer to the first element: std::vector
tzippy
  • 6,458
  • 30
  • 82
  • 151
0
votes
1 answer

error in using switch case

in the following code: switch(a) { case '+' : result=num1+num2; break; case '-' : result=num1-num2; break; case '*' : result=num1*num2; break; case '/' : result=num1/num2; …
0
votes
2 answers

C Double pointer Char is printing NULL. Don't Know what's going wrong?

This is display function to display the strings read in. void print(char **s,int T) { while(*s) { printf("i: String : %s\n",*s++); } } int main() { int T =0,i=0; char ** s, *c; printf("Enter number of…
Sandeep
  • 13
  • 4
0
votes
2 answers

Equality function with struct pointers

I have a graph and one parameter to the graph is an equality function. This is the code I've written: bool equalityFunction(void *char1,void *char2) { if(strncmp((char *)char1,(char *)char2, 20) == 0) return true; return…
Fjodor
  • 529
  • 1
  • 7
  • 19
0
votes
2 answers

Dynamic C - char pointers, strcpy, strcat

Here is my code: nodebug void sendLogPacketS(char *func, char *msg) { char * log; memset(log, 0, strlen(func) + strlen(msg) + 1); strcpy(log, func); strcat(log, ": "); strcat(log, msg); sendUDPLogPacket(log,…
Mike278
  • 35
  • 1
  • 3
0
votes
2 answers

"Heap Corruption Detected" when passing pointer to function then calling free() on the pointer

Visual Studio 2010 When I allocate memory for a char string, pass the string (pointer) to a function, then try to free the memory, I get a "Heap Corruption Detected" run-time error. I suspect this is a result of the function marking the memory as…
paperduck
  • 1,175
  • 1
  • 16
  • 26
0
votes
1 answer

How to fill array of character pointers with arguments taken from scanf?

I'm trying to write a VERY basic shell program in C. The problem I am facing is trying to fill my argv array of character pointers with the words taken from input. When I attempt to print out the contents of the argv array after attempting to fill…
trawww
  • 103
  • 1
  • 6
  • 14
0
votes
3 answers

c function is not working

So the following c function I implemented in segfaulting when I test it with the following code: char line1[] = "sw $s2, 0($s3)"; char* bc = removeAFromABC(line1); and this the the method that should return a char pointer = "$s2, 0($s3): char*…
letter Q
  • 14,735
  • 33
  • 79
  • 118
0
votes
2 answers

Writing data with ofstream crash C++

the IDE i'm using (visual studio 2012) doesn't show any errors or warnings, but i'm basicly trying to write binary data to a file called wizdata.bin and I have declared a few objects of my Wizard class. the Wizard class has few functions with 4…
0
votes
1 answer

Buffer overflows when using sprintf assigning to char array with char pointer as one of the inputs

I use sprintf to create a char array that can later be written out as a call to the system. char buffer[80]; char *ip = inet_ntoa(sa.sin_addr); short port = 1; sprintf(buffer, "Command with IP %s and port %d",ip, port); system(buffer); Now in…
Vincent Ketelaars
  • 1,069
  • 1
  • 14
  • 35