Sponsored Content
Full Discussion: Using const char*
Top Forums Programming Using const char* Post 302684139 by hergp on Thursday 9th of August 2012 07:56:01 AM
Old 08-09-2012
desc is not a constant pointer to char, but a pointer to a constant char.

If you want desc to be a constant pointer, write:
Code:
char * const desc;

If you want desc to be a constant pointer to a constant character, write:
Code:
 const char * const desc;

 

10 More Discussions You Might Find Interesting

1. Programming

Reference to a const

Can any one explain how the statement '2' in the following statements is a legal one. int & ref = 3; // Illegal statement - Compiler error. const int& ref=3 ; // Compile and executes properly. Thanks in Advance, Arun (1 Reply)
Discussion started by: arun.viswanath
1 Replies

2. Programming

diff b/w char const in C/C++

hi, what is the difference b/w char in C and C++.and give me the examples. Thanks... sarwan (3 Replies)
Discussion started by: sarwan
3 Replies

3. UNIX for Dummies Questions & Answers

int open(const char *pathname, int flags, mode_t mode) doubt...

hello everybody! I want to create a file with permissions for read, write, and execute to everybody using C, so I write this code: #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main(){ int fileDescriptor; fileDescriptor =... (2 Replies)
Discussion started by: csnmgeek
2 Replies

4. Programming

Adding a single char to a char pointer.

Hello, I'm trying to write a method which will return the extension of a file given the file's name, e.g. test.txt should return txt. I'm using C so am limited to char pointers and arrays. Here is the code as I have it: char* getext(char *file) { char *extension; int i, j;... (5 Replies)
Discussion started by: pallak7
5 Replies

5. Programming

concat const char * with char *

hello everybody! i have aproblem! i dont know how to concatenate const char* with char const char *buffer; char *b; sprintf(b,"result.txt"); strcat(buffer,b); thanx in advance (4 Replies)
Discussion started by: nicos
4 Replies

6. Programming

Optional non-const reference argument c++ ?

Is it possible to have a non-const reference variable as an OPTIONAL/DEFAULT parameter to c++ function ex void read(string &data,int &type=0 /*or something*/) ; so i will call read(data); //or int type; read(data,type); printf("Type =%d",type); I found one dirty workaround ... (2 Replies)
Discussion started by: johnbach
2 Replies

7. Programming

Questions about const

Hi all, I have some questions about functions. In a code I have (a .hpp file) there is this line which says: const Class_1_Name* Class_2_Name::MethodName(int ipart) const {return (ClassName*)_ref_to_method.At(ipart);} My questions are: What is the meaning of the two constants,... (2 Replies)
Discussion started by: eager2no
2 Replies

8. Programming

Why this const variable is not changing even after applying const_cast?

Hi In the following code, why the variable 'i' still retains the value 10 instead of 11? Why it is not possible to alter this variable's value? int main() { const int i = 10; *(const_cast<int*>(&i)) = 11; cout << i << endl; // Ans: 10 } (6 Replies)
Discussion started by: royalibrahim
6 Replies

9. Programming

error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially): xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’: xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’ The same error with all c++ constructors - gcc 4.4.4. If anyone can throw any light on... (8 Replies)
Discussion started by: GSO
8 Replies

10. Programming

Double to const char conversion

Dear all, I am using C and ROOT for programming. And I need to incorporate following in my code. char *fps=NULL; int dec=0,sign=0; float mean = h1->GetMean(1); //0.001298 fps= fcvt(mean,6 , &dec, &sign); I need to provide this mean as const char to some other function to get... (8 Replies)
Discussion started by: emily
8 Replies
explain_putw(3) 					     Library Functions Manual						   explain_putw(3)

NAME
explain_putw - explain putw(3) errors SYNOPSIS
#include <libexplain/putw.h> const char *explain_putw(int value, FILE *fp); const char *explain_errno_putw(int errnum, int value, FILE *fp); void explain_message_putw(char *message, int message_size, int value, FILE *fp); void explain_message_errno_putw(char *message, int message_size, int errnum, int value, FILE *fp); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the putw(3) system call. explain_putw const char *explain_putw(int value, FILE *fp); The explain_putw function is used to obtain an explanation of an error returned by the putw(3) system call. The least the message will con- tain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. value The original value, exactly as passed to the putw(3) system call. fp The original fp, exactly as passed to the putw(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: if (putw(value, fp) < 0) { fprintf(stderr, "%s ", explain_putw(value, fp)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_putw_or_die(3) function. explain_errno_putw const char *explain_errno_putw(int errnum, int value, FILE *fp); The explain_errno_putw function is used to obtain an explanation of an error returned by the putw(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. value The original value, exactly as passed to the putw(3) system call. fp The original fp, exactly as passed to the putw(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: if (putw(value, fp) < 0) { int err = errno; fprintf(stderr, "%s ", explain_errno_putw(err, value, fp)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_putw_or_die(3) function. explain_message_putw void explain_message_putw(char *message, int message_size, int value, FILE *fp); The explain_message_putw function is used to obtain an explanation of an error returned by the putw(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. value The original value, exactly as passed to the putw(3) system call. fp The original fp, exactly as passed to the putw(3) system call. Example: This function is intended to be used in a fashion similar to the following example: if (putw(value, fp) < 0) { char message[3000]; explain_message_putw(message, sizeof(message), value, fp); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_putw_or_die(3) function. explain_message_errno_putw void explain_message_errno_putw(char *message, int message_size, int errnum, int value, FILE *fp); The explain_message_errno_putw function is used to obtain an explanation of an error returned by the putw(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. value The original value, exactly as passed to the putw(3) system call. fp The original fp, exactly as passed to the putw(3) system call. Example: This function is intended to be used in a fashion similar to the following example: if (putw(value, fp) < 0) { int err = errno; char message[3000]; explain_message_errno_putw(message, sizeof(message), err, value, fp); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_putw_or_die(3) function. SEE ALSO
putw(3) output a word (int) explain_putw_or_die(3) output a word (int) and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2010 Peter Miller explain_putw(3)
All times are GMT -4. The time now is 07:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy