"suchat_cs2007" wrote:
> help me please, i have to cut string.
> Ex1: 1,000413,185019 ->
> x[0]=1
> x[1]=000413
> x[2]=185019
>
> Ex2. 1,00004123,4123421,73948473,3243847 ->
> x[0]=1
> x[1]=00004123
> x[2]=4123421
> x[3]=73948473
> x[4]=3243847
Something like this, perhaps:
int separate(char fred[100], char ethel[20][50])
{
int i = 0;
char *p = NULL;
p = strtok(fred, ",");
while (p)
{
strcpy(ethel[i], p);
p = strtok(0, ",");
++i;
}
return 42;
}
It's late, I'm tired, and I'm drunk, so that program
is probably full of errors and ommissions, and it's
totally untested. But I think it should give you the
idea of ONE way to preceed.
(Warning: research "strtok" thoroughly and force
yourself to fully understand how it works before
using it; it's a very tricky function.)
(I have a function along those lines being used in a
program at work, but I don't have access to the source
code at home. But it shows that while "strtok" does
have some drawbacks, it can still be useful in many
situations.)
> but i have create fn. for support many string pass
> this fn.
First make a function that can handle ONE string,
then call that function from your function that
processes MANY strings. Modularize! Many big
problems are solvable by just chopping them down
into smaller and smaller problems, until you have
only simple tasks left. You'll find that the
pseudocode you wrote in the chopping-down process
will heavily mirror the C code you'll use in your
final program.
(The other way, known as "spagetti code", is to
write everything in all one function. Not
recommended except for Obfuscated C contests.)
Cheers,
Robbie Hatley
lonewolfintj aatt pacbell dott net
triple-dubya dott tustinfreezone dott org