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
5 answers

Accessing a char* through a pointer

here is my problem. I have a class that regularly modifies a char*. There is another class, that needs to be able to read this value. So I want to pass the char* to the constructor of this second class, so that it can check the value, when required.…
Monday to Friday
  • 239
  • 5
  • 16
0
votes
2 answers

Fill char*[] from strtok

I have problems getting following Code to work. It parses a users input into a char*[] and returns it. However the char* command[] does not accept any values and stays filled with NULL... whats going on here? void* setCommands(int length){ …
Torhan Bartel
  • 550
  • 6
  • 33
0
votes
1 answer

Empty char* successfully converting into valid unsigned int64 game ID?? HOW?

I'm working on a game and I ran into a strange little issue... I was wondering if anyone here would be able to figure this out and explain it to me (it's eating me up!) Firstly, here's the relevant code. // even if this data is not set, it returns…
Jace
  • 3,052
  • 2
  • 22
  • 33
0
votes
3 answers

Strcmp does not behave as expected, Returns 0 when comparing two unequal strings

I am having understanding a weird behavior of strcmp function, which will be illustrated by the following code: #include #include using namespace std; int main() { char *p = "no"; cout << p << endl; …
0
votes
2 answers

Why am I getting this access violation?

I'm probably doing something stupid here, but it's been a while since I've worked in C++ and for some reason I keep getting an access violation when sprintf is called. Anyways, here's the code I'm using: char *value, *result; int len; result =…
Brandon
  • 890
  • 2
  • 13
  • 32
0
votes
1 answer

how to transfer contents of char[] to a String^ in C++/CLI

I've commandLine arguments in a C++/CLI program denoted by char* argv[]. I want to transfer all the contents getting concatenated to a String^ class. Code: String ^masterString = "Commands=>"; for(int i=0; argv[i] != nullptr; ++i) masterString +=…
-1
votes
1 answer

How to use Arduino's Serial.print with char* and const char* types

I require to build a simple Arduino function that returns either "char*" or "const char*" type and then I need to print that value. However, I'm facing a problem: when I try to print the function's return value, actually nothing gets printed. char…
Juan_David
  • 126
  • 2
  • 11
-1
votes
1 answer

What can I do to input the value in char*?

typedef struct inventory { char *name; int quantity; } invent; int main() { invent *one=malloc(sizeof(invent)); scanf("%s", one->name); ... } scanf() doesn't work. Is there any other way? I want how to input the value in char*.
-1
votes
2 answers

I try to understand what pointer variable is changing after xor operation

I have this little program that performs a xor operation over two char* but I can't tell if b1 is changed after the function call. When I try to do a std::cout the program does not print anything. #include #include #include…
Alex544
  • 25
  • 4
-1
votes
1 answer

Why does program return a seg fault when I input a pointer to a string literal but not when i input a pointer to an array?

When i pass the char * literal to trim() it seg faults but when I send an array pointer it works why is this not working? int main(void){ /* If instead I have a char s[100] = "Hi "; * it works as intended so why does it not work when…
kron maz
  • 131
  • 1
  • 6
-1
votes
1 answer

char *ptr ---> New to C

Declared char array (read-only): const char alpha [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; Given a char pointer called ptr and the alpha array declared above, how would I make ptr point to the letter 'D'? I think its ---> char *alpha[3]; because its…
ee ee
  • 3
  • 3
-1
votes
3 answers

Which is more efficient way for storing strings, an array or a pointer in C/C++?

We can store string using 2 methods. Method 1: using array char a[]="str"; Method 2: char *b="str"; In method 1 the memory is used only in storing the string "str" so the memory used is 4 bytes. In method 2 the memory is used in storing the string…
user1825567
  • 153
  • 1
  • 9
-1
votes
1 answer

Sort function stops working without any errors - C

This program is sorting the string inside the arrays. The function Sort is stoping after the 3rd time it runs with no compile errors int main(){ char * arrP1[] = { "father", "mother", NULL }; char * arrP2[] = { "sister", "brother",…
-1
votes
1 answer

strtok doesn't work with non-const char argument

I have this function that take a sentence and reverse each words. I have to modify the value in-place and the return value should be Null. I can't modify the main: int main() { char *string= "hello"; reverser(string); printf("%s\n",…
sworwitz
  • 19
  • 7
-1
votes
1 answer

String turns to garbage after using free()

I make a person in a person struct with typedef person_t: int main(int argc, char* argv[]) { person_t a; memset(&a, 0, sizeof(person_t)); person_set_name(&a, "Konrad Hoppenstauffer"); person_set_age(&a, 42); void…
prideHURTS
  • 43
  • 1
  • 5