Thread: International Phonetic ALphabet in C

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    27

    International Phonetic ALphabet in C

    Hi, I need to use characters from the International Phonetic Alphabet in my c program. More specifically, I need to save characters from this alphabet into arrays that are used in the program so that the characters can be printed to an outfile that the program generates. Does anyone know how I can get the program to recognize these characters?

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Use wchar.h header (and functions), wchar_t type, L"" prefixed strings and UNICODE codepoints (U+1D00 to U+1D7F are "phonetic extensions"). It's nice to see (ISO 9899, Anex D) that C supports multibyte charsets. For example:
    Code:
    #include <stdio.h>
    #include <wchar.h>
    #include <locale.h>
    
    int main( void )
    {
      setlocale( LC_ALL, "" );
    
      static const wchar_t msg[] = L"ˌɪntə(ː)ˈnæʃənl fəʊˈnɛtɪk ˈælfəbɪ";
    
      wprintf( L"%ls\n", msg );
    }
    PS: This works in Linux. Windows is a different matter: since Windows uses WINDOWS-1252 single byte charset or UTF-16 (if you change to wmain), you'll need to use Win32 API mutibyte conversion funcions or console API, probably.
    Last edited by flp1969; 09-21-2022 at 06:57 AM.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If your compiler has a wchar_t type, you should be able to input unicode symbols.
    Phonetic symbols in Unicode - Wikipedia

    How you input unicode depends on your OS.
    How to type Unicode characters in Linux? - Unicode Explorer
    Insert ASCII or Unicode Latin-based symbols and characters
    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.

  4. #4
    Registered User
    Join Date
    Aug 2010
    Posts
    27

    using Windows operating system

    Thanks for your responses?
    I am using Windows.
    Can you tell me how I can input unicode characters in Windows?

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    27
    flp1969- thanks for your suggestion. I tried implementing it by doing the following:
    a) I added the wchar.h header;
    b) I added setlocale (LC_ALL "");
    c) i added:
    wchar_t ngsound = L "ŋ";
    wprintf (L"%l\n", ngsound);

    When I ran the program, it got stuck on:
    wchar_t ngsound = L "ŋ";

    This line caused the following error message to be generated:
    [Error] invalid conversion from 'const wchar_t* tp 'wchar_t' [-fpermissive]

    Can you help me understand the meaning of this message?
    THANKS!

  6. #6
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    [QUOTE=rivkyfried1;1306268]This line caused the following error message to be generated:
    [Error] invalid conversion from 'const wchar_t* tp 'wchar_t' [-fpermissive][/code]
    Pay more attention...

  7. #7
    Registered User
    Join Date
    Aug 2010
    Posts
    27
    sorry - there was a typo in the error message.
    THe actual error message was, '[Error] invalid conversion from 'const wchar_t* to 'wchar_t' [-fpermissive]

    Sorry about that.
    If you can help out with what that message means, I'd be very grateful!

  8. #8
    Registered User
    Join Date
    Dec 2017
    Posts
    1,626
    flp isn't pointing out the typo. You're trying to store a pointer into a non-pointer. Try using single quotes around the character.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  9. #9
    Registered User
    Join Date
    Aug 2010
    Posts
    27
    john c. - thanks for your response.
    WHen I try single quotes, the program runs, but there is no output as a result of the wprintf.
    Just to be more clear, as a result of your comment, I changed the lines of code to the following:

    wchar_t ngsound = L 'ŋ';
    wprintf (L"%l\n", ngsound);

    I got no output from this. Can you advise? THANKS!

  10. #10
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    945
    %l is an incomplete format specifier. Try %lc instead.

  11. #11
    Registered User
    Join Date
    Aug 2010
    Posts
    27
    thanks for suggestion, christop. I just tried what you suggested, but it did not work.
    i changed the lines of code to:

    wchar_t ngsound = L 'ŋ';
    wprintf (L"%lc\n", ngsound);


    in the output - i can just see that a new line was started, i.e. the \n is being honored, but there is nothing else.

    Any other suggestions? THANKS!

  12. #12
    Registered User
    Join Date
    Aug 2010
    Posts
    27
    can anyone explain how to use UNICODE codepoints (referenced in flp1969's first post)?

  13. #13
    Registered User
    Join Date
    Aug 2010
    Posts
    27
    I think my issue is being caused by my compiler. I entered my code into an online C compiler called, Online GDB, and the code compiled correctly.
    The special characters were displayed correctly in the output. Does anyone know of a free c compiler with wchar_t type?
    THANKS!

  14. #14
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    945
    It might be an issue with the character encoding of the source file itself if it's different from what the compiler expects.

    Try wchar_t ngsound = L '\u014B'; in your code instead of the character itself.

    Here's a little guide on Unicode that I found: Unicode, Wide Characters, and All That. I haven't read it, but I've found Beej's networking guide to be very good.

  15. #15
    Registered User
    Join Date
    Aug 2010
    Posts
    27
    THanks, christop. I already tried using unicode codepoints.
    it doesn't work. I have no idea where to go from here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hashing, indexing and phonetic normalization for approximate str matching...
    By biterman in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 11-21-2006, 09:42 AM
  2. International Limits on Precision
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-20-2004, 06:32 AM
  3. International Compliance, ugh!
    By Sebastiani in forum Windows Programming
    Replies: 1
    Last Post: 12-04-2002, 06:18 PM
  4. International (scandinavian) characters?
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 01-11-2002, 06:14 PM

Tags for this Thread