Re: c equivilant to "copy"

From: pete (pfiland_at_mindspring.com)
Date: 01/13/05


Date: Thu, 13 Jan 2005 13:01:13 GMT

Krishanu Debnath wrote:
>
> Shagy wrote:
>
> >Greetings,
> >I've been trying to find an equivant c funtion to
> >the c++ copy function.
> >
> >Description:
> >
> > copy(char *cstring, size_t count, size_t offset);
> >
> > Copies "count" characters from a C-style string starting at offset.
> >
> >
> >Let's say I have the string "Hello There"
> >and I needed only the "llo" part from hello.
> > How would I accomplish this?
> >Using the c++ I could use the copy function.

> Probably what you are asking ...
>
> strncpy(dest, cstring + offset, count);
> dest[count] = '\0';
>
> assuming dest in large enough to hold 'count + 1' character.

Since you are not copying an entire string,
memcpy would work just as well as strncpy.

/* BEGIN new.c */

#include <string.h>
#include <stdio.h>

int main(void)
{
    char dest[sizeof "llo"];
    size_t count;

    count = sizeof dest - 1;
    memcpy(dest, "Hello There" + 2, count);
    dest[count] = '\0';
    puts(dest);
    return 0;
}

/* END new.c */



Relevant Pages

  • Re: CONVERT to HH:MM AM/PM
    ... funtion to accomplish what you are asking: ... create table x (cdatetime varchar(20)) ...
    (microsoft.public.sqlserver.programming)
  • Re: Macros in Excel
    ... Strictly you can't delete a row with a worksheet function such as if, but, ... given more detail on what you are actually trying to accomplish, ... > How can I write a macro that will delte a row in an IF funtion if the ...
    (microsoft.public.excel.programming)

Loading