Posted by Gazza on 2000-05-25
Many thanks for this,I'll give it a go
Cheers Gazza
----- Original Message -----
From: "Sharvil Nanavati" <snrrrub@xxxxx.xxx>
To: <glloyd@xxxxxxxx.xxxxx.xxx.xx>
Sent: Thursday, May 25, 2000 12:51
Subject: Re: Concatenate strings
> > hi all,i have a problem whereas I have a number of
> > strings (5) that i wish
> > to concatenate together each seperated by a comma ,
> > and beginning with a
> > comma, I have done it as so
> > char str[75];
> > strcat(str,comma);
> > strcat(str,s1);
> > strcat(str,comma);
> > .... strcat(str,s5);
> > is it possible to make this a bit cleaner,i hav
> > thought of a loop,but hav no
> > idea how to implement it,any suggestions appreciated
> > Cheers Gazza
>
> well, you could do it this way:
>
> char s[5][14]; file://however big the strings are...
> char str[75];
> int cnt = 0;
>
> while(cnt < 5)
> {
> strcat(str, ',');
> strcat(str, s[cnt++]);
> }
> strcat(str, ',');
>
> or you could use a for loop instead:
>
> for(cnt = 0; cnt < 5; cnt++)
> {
> strcat(str, ',');
> strcat(str, s[cnt]);
> }
> strcat(str, ',');
>
> Hope this helps...
> Cheers,
> Sharvil Nanavati
>
> __________________________________________________
> Do You Yahoo!?
> Kick off your party with Yahoo! Invites.
> http://invites.yahoo.com/
> >
>
Previous post | Next post | Timeline | Home