Sponsored Content
Top Forums Programming concat const char * with char * Post 302288387 by ujeshm on Tuesday 17th of February 2009 05:42:07 AM
Old 02-17-2009
Hi,

const char *buffer does not mean that buffer is a constant. It only says buffer points to a constant char. To declare buffer as a constant, you will have give,

char * const buffer;

Here in your code, you cannot give

char *b
sprintf(b,"result.txt");

Either you have to allocate memory to b and then use sprintf or strcpy or you can use,

b="result.txt";

To append something to buffer, you dont want to concatinate the new string with buffer, you may append the string to the array buffer points to. You cannot give strcat(buffer,b) as strcat does not allow const char * as its first argument.

You may try this

char b[1024]={"result.txt"}; //You may try dynamic allocation also
const char *buffer=b;

cout<<"\n Value of buffer 1 : "<<buffer<<endl; //It will be result.txt

strcat(b,",result1.txt");

cout<<"\n Value of buffer 2 : "<<buffer<<endl; //It will be result.txt,result1.txt

.
 

10 More Discussions You Might Find Interesting

1. 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

2. Programming

char *p and char p[].

Can anyone please explain me the difference between char *p and char p ? Thanks in Advance, Arun. (4 Replies)
Discussion started by: arunviswanath
4 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. Shell Programming and Scripting

How to replace any char with newline char.

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)
Discussion started by: mightysam
5 Replies

5. 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

6. Shell Programming and Scripting

how first char in odd line and second char in even line

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)
Discussion started by: tarunn.dubeyy
1 Replies

7. 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

8. Programming

Using const char*

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)
Discussion started by: kristinu
4 Replies

9. 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

10. Programming

Invalid conversion from char* to char

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
curl_printf(3)							  libcurl Manual						    curl_printf(3)

NAME
curl_maprintf, curl_mfprintf, curl_mprintf, curl_msnprintf, curl_msprintf curl_mvaprintf, curl_mvfprintf, curl_mvprintf, curl_mvsnprintf, curl_mvsprintf - formatted output conversion SYNOPSIS
#include <curl/mprintf.h> int curl_mprintf(const char *format, ...); int curl_mfprintf(FILE *fd, const char *format, ...); int curl_msprintf(char *buffer, const char *format, ...); int curl_msnprintf(char *buffer, size_t maxlength, const char *format, ...); int curl_mvprintf(const char *format, va_list args); int curl_mvfprintf(FILE *fd, const char *format, va_list args); int curl_mvsprintf(char *buffer, const char *format, va_list args); int curl_mvsnprintf(char *buffer, size_t maxlength, const char *format, va_list args); char *curl_maprintf(const char *format, ...); char *curl_mvaprintf(const char *format, va_list args); DESCRIPTION
These are all functions that produce output according to a format string and given arguments. These are mostly clones of the well-known C- style functions and there will be no detailed explanation of all available formatting rules and usage here. See this table for notable exceptions. curl_mprintf() Normal printf() clone. curl_mfprintf() Normal fprintf() clone. curl_msprintf() Normal sprintf() clone. curl_msnprintf() snprintf() clone. Many systems don't have this. It is just like sprintf but with an extra argument after the buffer that specifies the length of the target buffer. curl_mvprintf() Normal vprintf() clone. curl_mvfprintf() Normal vfprintf() clone. curl_mvsprintf() Normal vsprintf() clone. curl_mvsnprintf() vsnprintf() clone. Many systems don't have this. It is just like vsprintf but with an extra argument after the buffer that specifies the length of the target buffer. curl_maprintf() Like printf() but returns the output string as a malloc()ed string. The returned string must be free()ed by the receiver. curl_mvaprintf() Like curl_maprintf() but takes a va_list pointer argument instead of a variable amount of arguments. To easily use all these cloned functions instead of the normal ones, #define _MPRINTF_REPLACE before you include the <curl/mprintf.h> file. Then all the normal names like printf, fprintf, sprintf etc will use the curl-functions instead. AVAILABILITY
These function will be removed from the public libcurl API in a near future. They will instead be made "available" by source code access only, and then as curlx_-prefixed functions. See lib/README.curlx for further details. RETURN VALUE
The curl_maprintf and curl_mvaprintf functions return a pointer to a newly allocated string, or NULL if it failed. All other functions return the number of characters they actually outputted. SEE ALSO
printf(3), sprintf(3), fprintf(3), vprintf(3) libcurl 7.12 30 April 2004 curl_printf(3)
All times are GMT -4. The time now is 09:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy