"const char *foo means it cannot be modified" -> This is not completly correct. 'const char *foo' means foo is a pointer which points to a constant char (pointer to a constant variable, not a constant pointer variable). That means, the address in foo can be changed(foo is not a constant), but we cannot modify the value contained in the address held by foo(the value is considered as constant).
For example
In your code,
you got error in line 6 because, you are trying to change the value contained in the address held by 'dest'. That is if you remove the '*' it wont generate any errors. But the meaning will be different.
you got error in 7 because the dest is a const char * variable. memcpy does not allow const char * as its first argument (memcpy(void *,const void *,size_t))
The work around you are suggesting is similar to what I have given in my previous post. Only difference is you are asking to assign the address of the const char * variable to a char * variable and change the content of the char * variable. I declared the char * variable first and assigned its address to the const char * variable. After that I am also doing the same thing.
I think my previous post created some miss understandings in you. Sorry if it is so.
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)
Hi,
How to replace any character in a file with a newline character using sed ..
Ex:
To replace ',' with newline
Input:
abcd,efgh,ijkl,mnop
Output:
abcd
efgh
ijkl
mnop
Thnx in advance.
Regards,
Sasidhar (5 Replies)
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)
Hi
I m having ifconfig -a o/p like
sbanlab1:ksh# ifconfig -a | egrep "flags|inet" | awk -F' ' '{print $1,$2}'
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL>
inet 127.0.0.1
lo0:1: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL>
inet 127.0.0.1
bge0:... (1 Reply)
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)
I am writing some code in C++ to print a message using fprintf
Here is an example
void pr_desc(
FILE* stream,
int shift,
const char* desc) {
const char* format="%*s\e;
fprintf(stream,format,shift,"",desc);
}
I call it using
const char* desc;
... (4 Replies)
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)
Pointers are seeming to get the best of me and I get that error in my program.
Here is the code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define REPORTHEADING1 " Employee Pay Hours Gross Tax Net\n"
#define REPORTHEADING2 " Name ... (1 Reply)
Discussion started by: Plum
1 Replies
LEARN ABOUT HPUX
dtdts
Dt/Dts.h(file formats) Dt/Dts.h(file formats)
NAME
Dt/Dts.h -- data typing definitions
SYNOPSIS
#include <Dt/Dts.h>
DESCRIPTION
The Dt/Dts.h header declares the following structure:
typedef struct _DtDtsAttribute {
char *name;
char *value;
} DtDtsAttribute;
The header declares the following as functions:
DtDtsAttribute **DtDtsBufferToAttributeList(const void *buffer,
const int size,
const char *opt_name);
char *DtDtsBufferToAttributeValue(const void *buffer,
const int size,
const char *attr_name,
const char *opt_name);
char *DtDtsBufferToDataType(const void *buffer,
const int size,
const char *opt_name);
char *DtDtsDataToDataType(const char *filepath,
const void *buffer,
const int size,
const struct stat *stat_buff,
const char *link_path,
const struct stat *link_stat_buff,
const char *opt_name);
int DtDtsDataTypeIsAction(const char *datatype);
char **DtDtsDataTypeNames(void);
DtDtsAttribute **DtDtsDataTypeToAttributeList(const char *datatype,
const char *opt_name);
char *DtDtsDataTypeToAttributeValue(const char *datatype,
const char *attr_name,
const char *opt_name);
DtDtsAttribute **DtDtsFileToAttributeList(const char *filepath);
char *DtDtsFileToAttributeValue(const char *filepath,
const char *attr_name);
char *DtDtsFileToDataType(const char *filepath);
char **DtDtsFindAttribute(const char *attr_name,
const char *attr_value);
void DtDtsFreeAttributeList(DtDtsAttribute **attr_list);
void DtDtsFreeAttributeValue(char *attr_value);
void DtDtsFreeDataType(char *datatype);
void DtDtsFreeDataTypeNames(char **namelist);
void DtDtsLoadDataTypes(void);
void DtDtsRelease(void);
char *DtDtsSetDataType(const char *dirpath,
const char *datatype,
const int override);
Dt/Dts.h(file formats)