Thread: What function can I use to copy string from char to char?

  1. #1
    Registered User
    Join Date
    Aug 2017
    Posts
    23

    Question What function can I use to copy string from char to char?

    I mean if I have :
    Code:
    char* str_temp;
    str = "bla cla dla ela";
    how can i copy the string from str 5-8 char to str_temp?

    Thanks!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,112
    Well str_temp needs some memory allocated to it to begin with.
    Say
    str_temp[30];

    Then you can do things like this
    strncpy(str_temp,&str[5],3);
    str_temp[3] = '\0';
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2017
    Posts
    23
    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copy every single character from a char into another char.
    By Roscoe Araujo in forum C Programming
    Replies: 8
    Last Post: 06-06-2013, 03:22 AM
  2. Replies: 2
    Last Post: 12-02-2012, 05:25 AM
  3. Replies: 11
    Last Post: 06-16-2011, 11:59 AM
  4. Copy char array to char pointer
    By Suseela in forum C Programming
    Replies: 9
    Last Post: 08-06-2009, 12:49 PM
  5. char string copy
    By l2u in forum C++ Programming
    Replies: 8
    Last Post: 05-19-2006, 11:22 AM

Tags for this Thread