Advertisement

05.31.2008 at 11:14AM PDT, ID: 23447191
[x]
Attachment Details

realloc question

Asked by pothios in C Programming Language

Tags: c

hello. jus to confirm. after reading up on realloc, i get the concept that realloc does the following:
Please let me noe if im wrong :) thx



Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
char *message;
char * one = "hello";
message = realloc(message, (strlen(one)  +1) * sizeof(char));
strcpy(message, one);
char *two = "test";
//add the size of the second string to the size of the message 
message = realloc(message, (    (strlen(message) +1) + (strlen(two) +1)     ) * sizeof(char);
//add string two into message
strcat(message, two);
 
Loading Advertisement...
 
[+][-]05.31.2008 at 11:21AM PDT, ID: 21684561

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Tags: c
Sign Up Now!
Solution Provided By: Infinity08
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.31.2008 at 11:24AM PDT, ID: 21684577

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628