Go Back   The UNIX and Linux Forums > Top Forums > Programming


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-24-2012
Registered User
 
Join Date: Dec 2009
Location: London
Posts: 776
Thanks: 51
Thanked 6 Times in 6 Posts
Creating a string

I am trying to create a string from two strings using the following code and getting the following code and getting the warning


Code:
In file included from ./prgms/raytrac.cc:62:0:
baselib/clorfncs.hh: In function ‘void pr_hmisc(FILE*, int)’:
baselib/clorfncs.hh:494:21: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]


Code:
  char*  vbMsg01a = "important message. Each level can assume that all";
  const char*  vbMsg01b = " lower levels are also printing";
  strcat(vbMsg01a,vbMsg01b);
  const char*  vbMsg01c;
  strcpy (vbMsg01c,vbMsg01a);

I need to create a const char* vbMsg01c
Sponsored Links
    #2  
Old 06-24-2012
Registered User
 
Join Date: May 2012
Location: India
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Quote:
strcpy (vbMsg01c,vbMsg01a);
strcpy takes arguments in order char*, const char*, as does strcat.

Hence your code should be something like this:


Code:
const char*  vbMsg01d = vbMsg01a;
char* vbMsg01e; 
strcpy(vbMsg01e,vbMsg01d);
const char*  vbMsg01c = vbMsg01e;

Sponsored Links
    #3  
Old 06-25-2012
Registered User
 
Join Date: Oct 2007
Location: USA
Posts: 1,327
Thanks: 13
Thanked 108 Times in 103 Posts
Have you allocated memory for vbMsg01c before trying to store characters in it...
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Creating a blank string of a specified size kristinu UNIX for Dummies Questions & Answers 4 01-19-2012 01:00 PM
Creating 12 digit string value Pratik4891 Shell Programming and Scripting 16 09-27-2010 08:45 AM
Creating String from words in a file deepakthaman Shell Programming and Scripting 5 09-15-2009 01:37 PM
creating a delimiter string satish@123 Shell Programming and Scripting 0 05-21-2008 05:38 AM
creating folder when the string matches maximas Shell Programming and Scripting 2 10-04-2007 07:24 AM



All times are GMT -4. The time now is 10:11 PM.