Creating a string


 
Thread Tools Search this Thread
Top Forums Programming Creating a string
# 1  
Old 06-24-2012
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
# 2  
Old 06-24-2012
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;

# 3  
Old 06-25-2012
Have you allocated memory for vbMsg01c before trying to store characters in it...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Creating a .profile, displaying system variables, and creating an alias

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Here is what I am supposed to do, word for word from my assignment page: 1. Create/modify and print a... (2 Replies)
Discussion started by: Jagst3r21
2 Replies

2. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

3. UNIX for Dummies Questions & Answers

Creating a blank string of a specified size

I want to have a string which has n blank spaces For example set N = 3 create str = " " So the length depends on the value of N. I am in tcsh. (4 Replies)
Discussion started by: kristinu
4 Replies

4. UNIX for Dummies Questions & Answers

Creating a column based list from a string list

I have a string containing fields separated by space Example set sr="Fred Ted Joe Peter Paul Jean Chris Tim Tex" and want to display it in a column format, for example to a maximum of a window of 100 characters And hopefully display some thing like Fred Ted Joe ... (3 Replies)
Discussion started by: kristinu
3 Replies

5. Shell Programming and Scripting

Creating 12 digit string value

Hi Masters, here is my req I have to create a 12 digit string which includes the user i/p Like if user input 2334 then the string will be 233411111111 ,if the user inputs 23345 then the string will be 233451111111 , So we dont know how many digits will the user inputs output will be 12... (16 Replies)
Discussion started by: Pratik4891
16 Replies

6. Shell Programming and Scripting

Creating String from words in a file

Hi i have a file called search.txt Which contains text like Car Bus Cat Dog Now i have to create a string from the file which should look like Car,Bus,Cat,Dog ( appending , is essential part) String must be stored in some variable so i can pass it as argument to some other... (5 Replies)
Discussion started by: deepakthaman
5 Replies

7. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

8. UNIX for Dummies Questions & Answers

Creating a string array from a directory listing

Hi all, I'd like to create a string array from a long directory listing, extracting only files last modified on a specific date (e.g. Aug 08). I tried the following: aug8=`ls -ltr |grep 'Aug 08'` The result was an array (I think) but all of the output from the listing went to the first... (1 Reply)
Discussion started by: otes4
1 Replies

9. Shell Programming and Scripting

creating a delimiter string

hi i have a function printValues() { var=$# count=0 qName="" while do if then echo QManager Name $1 fi if then echo Cluster Name$2 fi if (( $count != 0 && $count != 1 )) then ... (0 Replies)
Discussion started by: satish@123
0 Replies

10. Shell Programming and Scripting

creating folder when the string matches

hi :confused:sorry last time , b4 im drafting the thread i was unexpectedly posted the thread see here is the program wat it will do is .. i have to create folder at the run time when the string matches ... what to do is im havin text file which carry the file name like ( EngCVer1pg1j01.TOP,... (2 Replies)
Discussion started by: maximas
2 Replies
Login or Register to Ask a Question