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

Storing a string in char pointer (using scanf)

#include #include #include int main(){ char *s1; char *s2; printf("Enter the string : "); scanf("%s",s1); printf("Enter the string : "); scanf("%s",s2); return 0; } I'm facing problems…
Deepak
  • 720
  • 1
  • 3
  • 12
0
votes
1 answer

When I write my own strchr function, there is a part in the return step that I don't understand

I'm trying to write my own strchr function for school, but there is something I don't understand. char *ft_strchr(const char *s, int c) { size_t i; size_t len; i = -1; len = ft_strlen(s); while (++i < len + 1) { …
user13101974
0
votes
1 answer

Issue opening a double pointer char element for reading it as text file

I'm new in C programming and I am trying to open a .txt file for reading it. I have a text file with different file names I want to read, each one in a different line. I created a function txt_to_stations() that reads this file and returns a double…
dacalite
  • 1
  • 1
0
votes
0 answers

Store contents of text file in a char* array in C++

I have to read the contents of a file, and store them in a char* array. I have the following, but when I output my char* array I don't get the full output of the file I read in. Am I incorrectly calculating the file size of my output array? Note: I…
yambo
  • 1,388
  • 1
  • 15
  • 34
0
votes
2 answers

How does a member initialization list work with char pointers?

I understand that a member initialzation list can be used to initialize objects and variables that have a known size. However, how does a member initialization list actually work with pointers, in particular const char* pointers, as in MyClass…
Engineer999
  • 3,683
  • 6
  • 33
  • 71
0
votes
1 answer

C++ memcpy/strcpy of char pointer to class member char pointer

i have a custom class, let's call it "Student" and a main method. I'm instanciating the class, and just want to output the content of the class. My programm crashes with a: Process finished with exit code 139 (interrupted by signal 11:…
Ulf Tietze
  • 57
  • 6
0
votes
1 answer

defining a string in C++ with const char *str="Hello";

I am a little confused here. In the statement const char *str="Hello";, str is a pointer to a char variable pointing to the first character 'H' of the string "Hello", so str should contain the address of the 'H' character. And yet, if I use…
0
votes
1 answer

Pointer address and address of variables to which pointer points

I am a newbie in c++ and my question may seem basic, but your answer could help me and help others. I created to char pointer myPointer1 und myPointer2 so const char *myPointer1 = "Hallo"; const char* myPointer2 = myPointer; I thought that pointer…
Hormesis
  • 11
  • 4
0
votes
1 answer

assignment from char * to a void *

working on a hacker-rank problem, the Printing tokens in C. My question does not come from the logic of the problem. i.e. finding the space and instead printing a '\n' rather it comes from the bit of code that is given. char *s; s = malloc(1024 *…
0
votes
1 answer

How can I trace a core dump in my C code?

I have a core dumped and I don't know why. Here is the code: #include int str_size(char *str) { int size = 0; for (int i = 0 ; str[i] != '\0' ; i++) { size++; } return (size); } int find_char(char c, char *str) { …
pulk66
  • 11
0
votes
3 answers

finding error in some cases of this char pointer?

We have to output New line for every space/gap in between strings.It's working good other than some test cases.(Range of length of string is between 0 to 1000.) #include #include #include #include int main()…
Gautam Goyal
  • 230
  • 1
  • 4
  • 16
0
votes
1 answer

i want to transmit data by byte unit and i think it's metter about endianness

i want to transmit data by bit unit so i was access data with char* variable. here is my code. int main() { //initiate int variable and casting with char* int a = 65; cout << a << endl; char* p = reinterpret_cast(&a); cout…
신승빈
  • 347
  • 3
  • 10
0
votes
1 answer

C/Lex char pointer printing value of other pointer as well

I am writing a lex program. I have initialized 3 char pointers. And then I am defining them to tokens if they satisfy the criteria. But when I print them afterwards, the first prints value of all 3, second of last two and last of itself. Why is this…
Shantanu Shinde
  • 932
  • 3
  • 23
  • 48
0
votes
2 answers

How do I convert a char pointer to lower case

I'm trying to fix my program...but I don't know how to fix this error "Bus error: 10". convert to lower case function: void toLowerCase(char* s){ while(*s){ if(*s >= 'A' && *s <= 'Z'){ *s = tolower(*s); ++s; …
Nam
  • 33
  • 5
0
votes
2 answers

Dereferencing double pointers in C

For the given code below : If we place name inside main, I get a segmentation fault. Why? Can we print each element of the matrix using p? Why does p++ jump by 8 bytes, while cp++ jumps to the next string? char *name[] = {"Arza", "Homes"}; //NULL…