linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Markus Rechberger <mrechberger@gmail.com>
To: Patrick Leslie Polzer <leslie.polzer@gmx.net>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: wcscat problem
Date: Thu, 19 Jan 2006 18:57:57 +0100	[thread overview]
Message-ID: <d9def9db0601190957v78b9ca71yaac25a0c7ef43d09@mail.gmail.com> (raw)
In-Reply-To: <20060119163800.1b45d984.leslie.polzer@gmx.net>

Hi,

some headers are missing within your source too.
Try to compile your version with -Wall

it should look like the code attached then it will work.

Markus

#define _GNU_SOURCE
#include <wchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main (int ac, char** av)
{
       wchar_t* ws = malloc(8);
       wcscpy(ws, (wchar_t*)"abc");
       wcscat(ws, (wchar_t*)"def");
       printf("%s/%s\n", ws, ws+4); /* "abc/def" [*] */


       char* s = malloc(8);
       strcpy(s, "abc");
       strcat(s, "def");
       printf("%s/%s\n", s, s+4); /* "abcdef/ef" */

       return 0;
}


On 1/19/06, Patrick Leslie Polzer <leslie.polzer@gmx.net> wrote:
>
> Hello list,
>
> why does wcscat not work like strcat does?
> It seems to be leaving the null byte in (C99 source):
>
>
> #define _GNU_SOURCE
> #include <wchar.h>
>
>
> int main (int ac, char** av)
> {
>         wchar_t* ws = malloc(8);
>         wcscpy(ws, (wchar_t*)"abc");
>         wcscat(ws, (wchar_t*)"def");
>         printf("%s/%s\n", ws, (void*)ws+4); /* "abc/def" [*] */
>
>
>         char* s = malloc(8);
>         strcpy(s, "abc");
>         strcat(s, "def");
>         printf("%s/%s\n", s, s+4); /* "abcdef/ef" */
>
>         return 0;
> }
>
> Why is this?  I also noticed the compiler (gcc4) takes "string steps"
> when performing pointer arithmetics with wchar_t pointers, that's why
> I needed to cast to void* in line [*].
>
> Leslie
>
>
> --
> gpg --keyserver pgp.mit.edu --recv-keys 0x52D70289
>
>
>


--
Markus Rechberger

  reply	other threads:[~2006-01-19 17:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-19 15:38 wcscat problem Patrick Leslie Polzer
2006-01-19 17:57 ` Markus Rechberger [this message]
2006-01-19 18:24   ` Patrick Leslie Polzer
2006-01-19 20:52 ` Steve Graegert
2006-01-22 10:30 ` Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d9def9db0601190957v78b9ca71yaac25a0c7ef43d09@mail.gmail.com \
    --to=mrechberger@gmail.com \
    --cc=leslie.polzer@gmx.net \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).