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

store string in char array assignment makes integer from pointer without a cast

#include int main(void){ char c[8]; *c = "hello"; printf("%s\n",*c); return 0; } I am learning pointers recently. above code gives me an error - assignment makes integer from pointer without a cast [enabled by default].…
frank_crane
  • 177
  • 2
  • 9
1
vote
3 answers

Problems with using char-pointers

I have a problem with this piece of code here. What my code is supposed to do is to assign bitfields to weekdays. For example, 0x00 for Monday, 0x01 for Tuesday and so on. Here is my code: #include typedef struct { unsigned int…
1
vote
3 answers

How to convert uint64_t to const char * in C++?

I have one method which accepts const char * as shown below - bool get_data(const char* userid) const; Now below is my for loop in which I need to call get_data method by passing const char *. Currently below for loop uses uint64_t. I need to…
john
  • 11,311
  • 40
  • 131
  • 251
1
vote
2 answers

Assignment of the values to the pointers inside while-loop (using )

Let's say I have 3 files with extension ".exe" files in the folder c:/. And I want to create 3 pointers of type char*, each of this pointer contains the file name of the .exe file. So, we have 3 pointers - 3 file names. But the output is what really…
chetmik
  • 13
  • 3
1
vote
1 answer

How to see contents of char * since printf won't work?

Here is a snippet of my code: #include #include "uhash.h" #include char * hash(item a) { const char * str= a.k; int len= strlen(str); int md_len; unsigned char md_value[EVP_MAX_MD_SIZE]; /* Buff to…
g0d
  • 57
  • 1
  • 7
1
vote
1 answer

C: array of char pointers not working as expected dynamically

I have the below snippets from my code where I am trying to use a dynamically allocated char * array to hold strings coming from stdin. char **reference reference = calloc(CHUNK, sizeof(char *)); I am using a temporary static array to first store…
Diwakar Sharma
  • 415
  • 1
  • 9
  • 26
1
vote
2 answers

Not getting right Output of Character Array

Possible Duplicate: Pointer to local variable #include using namespace std; char* func(); int main() { char* str; str = func(); cout<
priyanka
  • 13
  • 2
0
votes
5 answers

How do I modify a char** in another function

This is what I expect my string array s to be after the program is run: {"#0", "#1", "2"}. This is what I am getting: {"#2", "#2", "2"}. How do I modify this code so that I can get {"#0", "#1", "#2"} in the main after the function is executed? What…
Unyaya
  • 68
  • 7
0
votes
2 answers

Getting a list of strings from a function without dynamic memory

I am writing a C function GetDeviceList() which must return a list of device names found as strings somehow. The number of devices found and of course the device names themselves will vary each time the function is called. How the function gets the…
Engineer999
  • 3,683
  • 6
  • 33
  • 71
0
votes
1 answer

Frist few bytes of a char* are corrupted after creating it with malloc()

Whenever I create a char* with malloc(), the first few bytes get random data, which is different every time I compile the code. In this case, I wanted to concatenate 2 char* to create 1 char*. char *JoinStrings(char *str1, char *str2) { int…
Filip
  • 5
  • 3
0
votes
1 answer

ncurses displaying word at the center and make it into uppecase and lowercase

#include #include #include #include #include int main(int argc, char *argv[]){ int x,y,ch; if(argc != 2){ fprintf(stderr,"there is no value to be show\n"); exit(1); …
0
votes
1 answer

In plain C, could we implement generic functions using pointers to char instead of pointers to void?

In plain C, pointers to void are useful as arguments to generic functions, such as a generic quicksort, or a generic swap, etc., as seen here: Implementation of generic quicksort, etc. However, as the example of the generic partition function at…
Simon
  • 105
  • 1
  • 5
0
votes
1 answer

Making myfgets using char pointer as an input

char *myfgets(char *s, int n, FILE *in) { char ch; if (n<=0) { return s; } while (((ch = getc(in)) != '\n')) { if(ch == EOF){ return NULL; } else if (ch == '\n') { break; …
0
votes
1 answer

I get an error "Exception Thrown (challengeCodeAcademy.exe has triggered a breakpoint.)" whenever i run in debug mode

I already looked with a debugger and i get this error when it leaves the main() function. Here's my Code: #include char * trim(const char * _str) { char * newString = new char; for (int i = 0; i < 10; i++) { newString[i]…
NeeRaX
  • 13
  • 2
0
votes
1 answer

setting a character via index on a malloc char pointer not working

char * s_string = malloc(0); s_string = "1234567"; // s_string[7] = 'a'; // why not working ?... s_string = "123456a"; // but this works... printf("s_string = %s\n", s_string); s_string = "123412341234123412341234"; // does this do a…