-
November 11th, 2010, 03:05 PM
#1
copying a string
i have a question about copying a string.
basically i have a function that passes an array of characters, it will be a phone number and i want to copy the numbers into a string in the format of the first 3, then the next three then the last 4.
is there a way to set where i start my copy from in strcpy or is there another function i can use that will assist in doing this?
-
November 11th, 2010, 03:28 PM
#2
Re: copying a string
I don't understand... What do you mean, "copy the numbers into a string in the format of the first 3, then the next three then the last 4."? You want three separate strings?
Viggy
-
November 11th, 2010, 03:29 PM
#3
Re: copying a string
Originally Posted by turlisk
i have a question about copying a string.
basically i have a function that passes an array of characters, it will be a phone number and i want to copy the numbers into a string in the format of the first 3, then the next three then the last 4.
is there a way to set where i start my copy from in strcpy or is there another function i can use that will assist in doing this?
Is your string a char array, or a string?
If it's a char array, just add the offset for the start position you want to the source pointer you pass to strcpy.
If it's a string, use substr().
-
November 11th, 2010, 03:57 PM
#4
Re: copying a string
I guess he means that the C-string number is like 123-456-7890 and he wants a copy without the -.
Something like this maybe
Code:
char in[] = "123-456-7890";
char out[sizeof(in)-2]={0};
memcpy( &out[0], &in[0], 3 );
memcpy( &out[3], &in[4], 3 );
memcpy( &out[6], &in[8], 4 );
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|