const « char « C Data Type Q&A

Home
C Data Type Q&A
1.binary
2.bit
3.byte
4.char
5.character
6.decimal
7.Development
8.float
9.hex
10.integer
11.prime
12.random
13.struct
C Data Type Q&A » char » const 

1. Why does this allow promotion from (char *) to (const char *)?    stackoverflow.com

Given that scanf has (const char *) in the documentation from Microsoft and the answer to this question what the heck is going when I do the same ...

2. How come XDrawString doesn't take "const char *"?    stackoverflow.com

looking at the declaration for XDrawString from X11, it is

int XDrawString(Display *display, Drawable d, GC gc,
                ...

3. Difference between const char* p and char const* p    stackoverflow.com

Possible Duplicate:
what is the difference between const int*, const int * const, int const *
    Are there any Difference between ...

4. why a "char*" can point to a "const char*"?    stackoverflow.com

the following code can be compiled correctly on both VC or gcc:

char *str = "I am a const!";
str[2] = 'n';
however, obviously there is a run-time-error. Since "I am a const!" is ...

6. Usage of const char * const name    bytes.com

Hi Banfa, Thanks to the reply. You are absolutely correct about integer. So that only already I have commented the second line of my program. But, like that I should not able to change the character pointer value also. But I am able to change it. (Refer line number 3 of my program). My moto is I should not able to ...

7. const char* and char* concatenation    bytes.com

foo and bar are addresses of characters. You are trying to add addresses and this makes no sense. You need to work with contents of these strings and not their addresses. What you need to so is: 1) count the number of characters in the string foo. 2) count the number iof characters in the string bar. 3) allocate memory for ...

8. const char*    bytes.com

Jrdman

9. Preprocessor: convert __LINE__ to const char*    bytes.com

Hi, I have a problem with the preprocessor. I have written my own little assert macro. This is supposed to log a message (with log4cxx): #define LogAssert(Expression) \ if (Expression) { \ LOG4CXX_FATAL(log4cxx::Logger::getRootLogger(), "LogAssert: " \ #Expression " in file " __FILE__ ", line " #__LINE__ "."); \ ::exit(1); \ } Unfortunately, the preprocessor is only quoting marcro arguments. In my ...

10. converting a char* to a const char*    bytes.com

Sean Farrow wrote: Hi: What is best and safest way of converting a char* to a const char *? Can I use const_cast? No const_cast is rather technical and best not used (unless you *really* understand what its purpose is). In a nutshell, if you have an object that you know is not const but it appears as const via e.g ...

11. convertion form char** to const char** error    bytes.com

Hi, I have a question regarding the conversion (in c or c++) from char** to const char**. The fallowing code refuses :) to compile with g++ (and others): char **p; const char **q = static_cast(p); or, exact the same situation: void f(const char **p) {} int main() { f(p); return 0; } And I don't understand why. It should work ...

12. [Q]const char *const * ??    bytes.com

Hi Guys, When a function has following arg type, update_data(const char *const * update_list,...) exactly what object type update_list can take? For example, I can call update_aaa() using following variale as an arg: const char *updatelist_default[]={ "aaa", "bbb", NULL}; Then, why the 2nd 'const' is necessary ? I mean, update_data(const char * * update_list,...) would work. But actually not!

13. std::wcout and const char *    bytes.com

Hi! In converting applications from ansi to unicode, it is a problem that the std::wcout accepts a const char * without complaining compile time. This compiles and runs: ------------------------------ const char *lookup() { return "Hello world"; } std::wcout << lookup(); ------------------------------ I would like it to fail compile time, so I can properly convert cases like this to unicode in a ...

15. const char** to char*const[]?    bytes.com

Hello, I have two functions: void function1(char* const names[]); void function2(const char** names) { //do other stuff function1(names); //do more stuff } My compiler (VS2005 C++) gives me "cannot convert parameter 1 from const char** to char * const[]", which I'd expect. My question is how do I convert from const char** to char* const[]? It's been a while since I've ...

16. How to literate a const char*    bytes.com

Hi, how can I literator a const char*? I have this code, but it results in an infinite loop. It never exits the while (p1 != '\0') loop void teststr( const char *str1) { char* p1 = (char*)str1; while (p1 != '\0') { //.... p1 ++; } } and i call teststr like this: teststr("http://www.cnn.com"); Can you please tell me why ...

17. assigning const char* to char*    bytes.com

Hi, This is a very simple question but I couldn't find it in your FAQ. I'm using VC++ and compiling a C program, using the /TC flag. I've got a function for comparing two strings int strspcmp(const char * s1, const char * s2) { char* pS1 = s1; char* pS2 = s2; ... ... } As you can see, I ...

18. Converting between const char* and char*    bytes.com

How do I convert the type const char* to type char*? I have an input string ("input_string") of class string. I need to convert this to type char* in order to use it in a call to the strtok() function. However, the .c_str() string class function returns type const char*. The relevant code may be found below. My compiler returns the ...

19. (char *) to (const char *) is also dangerous but allowed?    bytes.com

C stops the conversion from (char **) to (const char **). c-faq.com sec 11.10 has explanation on this point. But, for example, even the conversion from (char *) to (const char *) brings the same dangerous as in the previous conversion. Why the latter simple but dangerous one is allowed in C? $ cat f1.c int main(void) { const char c ...

20. how to deal with the translation from "const char * " to "const unsigned char *"?    bytes.com

On Jan 28, 11:21 pm, "" ("abcdg"); sizeof(reinterpret_cast(p)); ----------------------------------------------------------------------- ---------------------------------------- > the compiler tells me that "reinterpret_cast from type "const char * " to type "unsigned char *" casts away constness " At this point you stop wrestling with the C++ bullshit and just use a C style ...

21. const char* as a static member    bytes.com

"Alex Vinokur"

22. const char* to char* conversion    bytes.com

Hi! I've got this: string str1; char * str2; .... str1 = "whatever"; .... str2 = (char *)str1.c_str(); Is this ok? Is there any other better way to do the same? I'm not sure if I'm doing the rigth thing, so I hope you can help me with this. Thanks in advanced!

23. weirdness with std::map    bytes.com

lada77@yahoo.com All, Just wondering if one of you very helpful guru's out there could comment on some odd behaviour I am seeing. I'm betting it is something obvious but I am not experienced enough to tell right away. Here is my code snippet and the results that I am seeing: #include #include int main(int argc, char *argv[]) { string ...

24. char * const &szKey    bytes.com

Greetings, Could anyone explain to me how the parameter type works here? I am also interested in the technical details of what is actually happening on the stack. I have never seen a "char * const &szFoo". I usually just use "char *pszFoo" whenever I want to pass a string, or maybe "const char *pszFoo" if I know that I won't ...

25. const char* reassignment    cboard.cprogramming.com

26. const char *    cboard.cprogramming.com

27. convert int to const char *    cboard.cprogramming.com

Code: #include #include char *cprog_strrev(char *s, size_t n) { size_t i, j; for (i = 0, j = n - 1; i < j; i++, j--) { char save = s[i]; s[i] = s[j]; s[j] = save; } return s; } char *cprog_itos(int value, char *buf, size_t size, int radix) { const char *digits = "0123456789ABCDEF"; int sign = ...

28. concatenate 2 const char * problem    cboard.cprogramming.com

No, essentially what's going on is this Code: main.c int main() { //call function in external file extern.c extern(__FILE__,__LINE__,__func__) } extern.c int extern(const char*file, int line, const char *func) { //print file, line, func //print this file's file, line, func } The goal is to macro the extern() function call so it only has ONE parameter, not known to the caller ...

29. Newbie question: char const **    cboard.cprogramming.com

This is incorrect. The items in your code are constant strings, which you store in non-const char. As soon as it is written to, your program will likely crash. Furthermore, the last "\0" is an empty string, identical to "", except that the former contains two 0-bytes. I expect it should read NULL, although granted, it depends on the called function ...

30. Difference between char *str1 & const char *str2    cboard.cprogramming.com

31. Text (const char*)    cboard.cprogramming.com

const char *pointer; { pointer = "This is a text"; } // Would it still be legal and safe to assume pointer still reffer to // "This is a text"?(outside of brackets) // I would guess so, but that would mean text-constants are // guaranteed not to get overwritten even when out of scope.

32. Difference between const char * and char const *    cboard.cprogramming.com

33. Char/Const char    cboard.cprogramming.com

34. How to stop processing static const unsigned char * const tab[][]    cboard.cprogramming.com

static const unsigned char *const Msgs[1][16] = { { "Please", "go to the", "user menu", "- tanks -", "", "", "", "", "", "", "", "", "", "", "", "" } }; . . . void fun(void) { unsigned char i; for (i = 0; Msgs[0][i]; i++) { printf("%s", (unsigned char *)Msgs[0][i]); } }

35. const char * vs char *    cboard.cprogramming.com

In other words: Code: { const char *p = "initial"; p = "reassignment"; strcpy(p, "copying"); /* invalid */ } { char *const p = "initial"; p = "reassignment"; /* invalid */ strcpy(p, "copying"); } { const char *const p = "initial"; p = "reassignment"; /* invalid */ strcpy(p, "copying"); /* invalid */ } Of course, the second strcpy() is actually invalid ...

36. info: mkdir(const char *path)    cboard.cprogramming.com

Hello :-) I'm an engineer (mechanic) so Cprogramming is not my job, and my question can sound silly to most of you. Please understand and thank you in advance. My problem is: I get a FileList.txt on argv[1], for example: C:\F00\Pippo_Folder\Pippo_Data\PippoData001.dat C:\F00\Robin_Folder\Robin_Data\RobinData005.dat C:\F00\Batman_Folder\Batman_Data\BatmanData100.dat etc.. I want to fopen(_argv[1],"r") then fopen(first_file,"rb"); and that's OK, I can do that. My problem is that ...

37. convert char* to const char*    cboard.cprogramming.com

38. difference between: const char *, char *    cboard.cprogramming.com

#include #include #define GET_NUM_ELEMENTS(x) (sizeof(x) / sizeof(x[0])) int main(void) { const char *cStr = "Stuff"; char *str = "Stuff"; const char *cStrArray[] = { "Um", "Some", "Words" }; char *strArray[] = { "Um", "Some", "Words" }; for(register unsigned int i = 0; i < GET_NUM_ELEMENTS(StrArray); i++) printf("%s ", strArray[i]); getch(); return 0; }

39. question on puts(const char *)    cboard.cprogramming.com

#include int main(void) { int n, int i = 0; char part_code[10]; /* input part code */ char part_qty[10]; /* input part quantity */ char part_desc[10][81]; /* input part description */ printf("enter part code or Z to quit:"); scanf("%c", &part_code[i]); while (part_code[i] != 'Z') { printf("\nEnter part %c quantity: ", part_qty[i]); scanf("%d", &part_qty[i]); printf("\nEnter part %c 's Description: ", part_desc[i]); ...

40. Const char as class member    forums.devshed.com

41. char*const and const char *    forums.devshed.com

'hello' is the name of the pointer, not the variable to which it points. Its value IS the address to which the pointer points. Changing the value of 'hello' changes WHERE the pointer points. 'Hello' is a mnemonic for the address of the pointer, the contents of the pointer are the address of another thing.

42. Implicit ctor call to convert from const char* to my own class.    forums.devshed.com

I have a constructor that takes a const char*, if I have a function that takes const myclass&. and I pass a const char* to it, shouldn't the ctor for const char* implicitly be called to create a temporary object of myclass and pass it to the function? I get an undefined reference error. I have myclass operator= (const myclass&) defined, ...

43. converting const char* to char*    forums.devshed.com

Are you sure that putenv() makes no changes to its argument? If there is any chance you should copy the string into another buffer and use that buffer as the argument instead. const may be relatively new, but it has been around for nearly 20 years, so most programmers should know about it.

44. How to convert unsigned char to const char    forums.devshed.com

Hi to all! First to say, I have no idea at all about C++, but i'm on the way to create a FileMaker plugin that enables the possibility to show help about some topic. Now I'm getting everytime the error : error C2664: 'atoi' : cannot convert parameter 1 from 'unsigned char' to 'const char *' Conversion from integral type to ...

45. Dreaded char* const problems    forums.devshed.com

Let me start by saying I am using Emin Martinian's my_hash_map for my hash_map. I seem to be having a problem with calling the find function and passing a value to the char* const & parameter. find(char* const &); I use the std::string for most of my lookups, but with this guy, I seem to be having a problem. // Pseudo ...

46. const char* Vs char*    forums.devshed.com

Declaring a parameter const char*prevents the function being called from moving the pointer. The data pointed to however may be changed. In C++ a reference parameter char& does a similar job and may be clearer. A char* will work, but the protection is not there, and does not indicate intent to the user of the function. Clifford

47. int *getInteger(int **ptr, const char *prompt)    forums.devshed.com

I have to write a function that gets a pointer from a user. kinda like scanf() but understands spaces(I guess). So the type of function is: int *getInteger(int **ptr, const char *prompt); Question 1: I know that char is ** ptr going to = &somevar I'm not sure what int *prompt is going to be. (maybe %d?) Question 2: I have ...

48. char* to const char*    daniweb.com

50. char* vs const char*    daniweb.com

Well that really depends on whether myFunc was declared with char* because - the programmer was too lazy to say const - because the function does actually modify the string. The first is fixed by fixing the code. The second is fixed by making a modifiable copy of the string constant, then passing that to myFunc. Neither involves a cast. > ...

51. Converting Int to Const Char    daniweb.com

52. AnsiString to Const Char*    daniweb.com

53. const char to char problem    codeproject.com

54. do I have to free() a const char * ?    codeproject.com

55. How to convert const char* to c#    codeproject.com

56. Const char error    tek-tips.com

Hi!I have made a const char as follows:char const Ccode [] = "#include \n""#include \n""#include \n""include \n""#include \n""\n""#define TCLGO TCL_GLOBAL_ONLY\n""main(int argc, char *argv[])\n""{\n"" Tcl_Interp *interp;\n" " Tk_Window mainWindow;\n"" Tk_Window tkmain;\n" " int error;\n"" char *trace;\n"" \n""/* first we create a ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.