Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Question

Status
Not open for further replies.

gonzilla

Programmer
Apr 10, 2001
125
US
How do you strcat a string with "n" number of other strings of "x" length so that the final string only has "z" length? As an example:

Let's say I have 5 strings processed. They are these lengths:

p_str[0] 80
p_str[1] 65
p_str[2] 100
p_str[3] 10
p_str[4] 18

Now I want to load another string called final_string[190] with as much of the 5 strings processed as possible. So, with this example I will be able to get all of p_str[0] and p_str[1] and 45 of p_str[2] in there, not couting the '\0' and the newline from fgets. I have thought doing something like getting the strlen of each string before it is concatenated and using strncat with the amount of space I have left, subtracting when the amount left is less than the length of the current string. I think it's possible, but there must be a MUCH better way. Any help?
Thanks.

-Tyler
 
What I'd do is write my own function that would automate this by checking the length for you and calling strcat or strncat automatically. This way you only have to worry about writing the code once.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top