Question about connecting strings and

This is a discussion on Question about connecting strings and

Thread: Question about connecting strings and \0

within the C Programming forums, part of the General Programming Boards category; There's a string with four numbers and a

Thread: Question about connecting strings and \0

sign, which's making it needing array size of 5: Code: char ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    6

    Question Question about connecting strings and \0

    There's a string with four numbers and a \0 sign, which's making it needing array size of 5:
    Code:
    char string[5] = "1234";
    Now, i want to connect three of these strings with sprintf:
    Code:
    sprintf(StringsConnected,"%s%s%s",string,string,string) // probably not the best way, but still ...
    Now, what array size should string StringSonnected have?
    - 13, for 123412341234 and \0 or
    - 15, for 1234\01234\01234\0 or
    - even 16, for 1234\01234\01234\0\0?

    Thanks!

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > - 13, for 123412341234 and \0 or
    Is the correct answer.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    6
    Thanks