why doesn't wprintf work

  • Follow


$ gcc --version|head -1 ; cat /etc/redhat-release
gcc (GCC) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
Fedora Core release 2 (Tettnang)

$ echo $LANG
en_US.UTF-8

$ cat wide.c
#define _GNU_SOURCE
#include <stdio.h>
#include <wchar.h>
int main(int argc, char **argv)
{
                                                                                
    wprintf(L"Hello, %s\n", L"world");
    return 0;
}

$ gcc -o foo foo.c -Wall

$ ./foo
Hello, w
0
Reply carloschoenberg 6/5/2004 11:34:17 PM

carloschoenberg@yahoo.com wrote:
> $ gcc --version|head -1 ; cat /etc/redhat-release
> gcc (GCC) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
> Fedora Core release 2 (Tettnang)
> 
> $ echo $LANG
> en_US.UTF-8
> 
> $ cat wide.c
> #define _GNU_SOURCE
> #include <stdio.h>
> #include <wchar.h>
> int main(int argc, char **argv)
> {
>                                                                                 
>     wprintf(L"Hello, %s\n", L"world");

       wprintf(L"Hello, %S\n", L"world");

>     return 0;
> }
> 
> $ gcc -o foo foo.c -Wall
> 
> $ ./foo
> Hello, w


-- 
Thomas M. Sommers -- tms@nj.net -- AB2SB

0
Reply T 6/6/2004 1:35:00 AM


T.M. Sommers wrote:

>>     wprintf(L"Hello, %s\n", L"world");
>
>       wprintf(L"Hello, %S\n", L"world");

    You want '%ls'. My man page clearly states that '%s' still means normal 
C-style strings.

    DS


0
Reply David 6/6/2004 1:54:58 AM

On Sat, 05 Jun 2004 18:54:58 -0700, David Schwartz wrote:

> T.M. Sommers wrote:
> 
>>>     wprintf(L"Hello, %s\n", L"world");
>>
>>       wprintf(L"Hello, %S\n", L"world");
> 
>     You want '%ls'. My man page clearly states that '%s' still means normal 
> C-style strings.
> 
>     DS
Seems like someone should file a bug on the linux man pages, seems
wrong/outdated, 
It says things are similar to printf except 's' and 'c'..
"s    If no l modifier is present: The ''const char *'' argument is
expected to be a pointer to an array of character type  (pointer
to a string) containing a multibyte character sequence beginning
in the initial shift state.
....."
(no mention of 'S')
printf manpage says among others:
"S  (Not in C99, but in SUSv2.) Synonym for ls. Don't use."

0
Reply iso 6/6/2004 2:33:49 AM

Nils O. Sel�sdal wrote:

> Seems like someone should file a bug on the linux man pages, seems
> wrong/outdated,
> It says things are similar to printf except 's' and 'c'..
> "s    If no l modifier is present: The ''const char *'' argument is
> expected to be a pointer to an array of character type  (pointer
> to a string) containing a multibyte character sequence beginning
> in the initial shift state.
> ...."

    This is correct. Don't confuse multibyte with wide.

    DS


0
Reply David 6/6/2004 2:44:02 AM

On Sat, 05 Jun 2004 19:44:02 -0700, David Schwartz wrote:

> Nils O. Sel�sdal wrote:
> 
>> Seems like someone should file a bug on the linux man pages, seems
>> wrong/outdated,
>> It says things are similar to printf except 's' and 'c'..
>> "s    If no l modifier is present: The ''const char *'' argument is
>> expected to be a pointer to an array of character type  (pointer
>> to a string) containing a multibyte character sequence beginning
>> in the initial shift state.
>> ...."
> 
>     This is correct. Don't confuse multibyte with wide.
Ah, ofcourse. My mistake.
0
Reply iso 6/6/2004 11:39:50 AM

On 5 Jun 2004 16:34:17 -0700, carloschoenberg@yahoo.com wrote:

>	wprintf(L"Hello, %s\n", L"world");

That should be:

	wprintf(L"Hello, %ls\n", L"world");

Without the l modifier, the "argument is expected to be a pointer to an
array of character type (pointer to a string) containing a multibyte
character sequence beginning in the initial shift state" according to
the Linux man page.

Cheers // Fredrik Roubert

-- 
M�llev�ngsv�gen 6c  |  +46 46 188127
SE-222 40 Lund      |  http://www.df.lth.se/~roubert/
0
Reply roubert 6/7/2004 11:38:46 AM

6 Replies
526 Views

(page loaded in 0.145 seconds)


Reply: