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
1
vote
2 answers

C++ Convert the binary data read from a file to a char pointer

I am trying to achieve converting a binary content read from a file to a byte continuously . My file samplefile.bin contains 16bytes and this is in the form of binary . In the Hexed.it it will show like this . What I needed in this case is I need…
Vishnu CS
  • 748
  • 1
  • 10
  • 24
1
vote
2 answers

Using free() for char-pointer in struct

typedef struct inventory { char *name; int quantity; double price; struct inventory* next_inventory; } invent; int main(void) { invent *one=malloc(sizeof(invent)); invent *two=malloc(sizeof(invent)); invent…
1
vote
0 answers

read file with getline(char *) c++

I have this code: try{ ifstream file("Students.txt", ios::in); if (!file) throw MyExceptions(); int begin = file.tellg(); file.seekg (0, ios::end); int end = file.tellg(); int size = end - begin; char *charField; int…
1
vote
1 answer

why the warining deprecated conversion from string constant to 'char*' occured in the bellow program

I created a class called person with the public member function fill_data which takes two arguments as char array and int . I passed the arguments like this fill_data("tushar",30); but there shows a warning deprecated conversion from string…
play store
  • 393
  • 1
  • 5
1
vote
1 answer

Pointer of ^Pchar to array of PChar

when i migrate from Delphi 6 to Delphi 10.2 Tokyo i get error when i try to casting pointer of ^PChar to array of PChar type PServEnt = ^TServEnt; TServEnt = packed record s_name: PChar; // official service name …
1
vote
3 answers

Adding an int into middle of char* (In C)

Was wondering how it were possible to have an int in the middle of a char*, as such: char * winning_message = "Congratulations, you have finished the game with a score of " + INT_HERE + " Press any key to exit... …
mvngmnd
  • 15
  • 5
1
vote
5 answers

Understanding the dereference, address-of, and array subscript operators in C

I have argv[] defined as a char *. Using the following printf statements: printf("%s\n",argv[1]); // prints out the entire string printf("%p\n",&argv[1]); // & -> gets the address printf("%c\n",argv[1][0]);// prints out the first…
DCR
  • 14,737
  • 12
  • 52
  • 115
1
vote
3 answers

working with char pointer and integer pointer

My question is about dereferencing a char pointer Here is my code - #define MAX 10 char s[80]="Hello"; int main(){ char *stackValue; stackValue=&s;//here I assined the address of s to stackValue if(!stackValue){ printf("No…
tiwarinitin94
  • 114
  • 2
  • 13
1
vote
1 answer

C++ MFC: Memory Leak When Creating CString From Char*

I am getting a memory leak when I run try to read from Clipboard. Sample code: void SomeFunction() { OpenClipboard(nullptr); HGLOBAL hglb = GetClipboardData(CF_TEXT); char* ch = static_cast(GlobalLock(hglb)); CString…
10100111001
  • 735
  • 15
  • 31
1
vote
2 answers

linked list char pointer scanf input

I'm attempting to input multiple times to a char pointer in linked list using scanf. but every time I enter new input the name changes in all the fields. here is my linked list: struct node { struct node *next; int level; char *name; }; here is my…
Poorya
  • 1,291
  • 6
  • 27
  • 57
1
vote
1 answer

String manipulation code using char ** pointer gives unexpected result

I was trying to implement a string parsing code for that I need substring of the given string so I deed the following: The header file is : test.h #ifndef header_file #define header_file #include #include int increment(char…
Abhijatya Singh
  • 642
  • 6
  • 23
1
vote
1 answer

Getting no segmentation fault when exceeding the size that was allocated for a char *

I use malloc to allocate n (string length of y) bytes for x. However after copying y to x , I added 3 more characters including '\0' in x and i got no error. Shouldn't I get an error for trying to assign values to unallocated memory since I've…
MattSt
  • 1,024
  • 2
  • 16
  • 35
1
vote
2 answers

memcpy causing program to crash with initialized destination

I was working on a larger program and memcpy was causing it to crash. I replicated the situation in a small program and it does the same thing. I noticed that for some reason this program runs fine // Runs fine #include int main() { …
Xerif917
  • 132
  • 2
  • 10
1
vote
2 answers

Trying to Convert String to Character Pointer?

I've been trying everything under the sun to do the simple following: 1) Receive an input string from stdin. 2) Convert it to a char pointer so I can pass to a tabling/palindrome finding function. I'm confident in the latter part of step 2, but it's…
Rome_Leader
  • 2,518
  • 9
  • 42
  • 73
1
vote
6 answers

How is a char pointer an entire string?

Let's say I have the following string: char *my_string = "Stack"; As far as I know char * holds the memory address of the first character of the string "Stack". In the computer memory it might be represented as the following: …
jkigel
  • 1,592
  • 6
  • 28
  • 49