Sponsored Content
Top Forums Programming Pure C function pointer on printing vowels twice Post 302997654 by yifangt on Wednesday 17th of May 2017 04:54:17 PM
Old 05-17-2017
Thanks Don and corona688!
I think my problem is my mis-understanding of the function putchar(c) so that I re-wrote it with putc() which helped me understand it.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>

/*Print a char twice like putchar, return char if successful, or EOF on error.*/

int putcharTwice(int c)
{
    if (putc(c, stdout) == EOF || putc(c, stdout) == EOF)  {//Q1
    return EOF;
    } else {
    return 0;        //NOT return c;
    }
}

#define NUM_CHARS (UCHAR_MAX + 1)    //UCHAR_MAX is in limits.h

  int (*table[NUM_CHARS]) (int);   //Q2, So moved outside main() to see this function pointer

int main(int argc, char **argv)
{
/*This declares table as array of function pointers */
    int i;
    int c;

    for (i = 0; i < UCHAR_MAX; i++) {
    // default is to call putchar 
    table[i] = putchar;
    }

    // but lower-case vowels show up twice 
    table['a'] = putcharTwice; //Q3, and following 4 lines
    table['e'] = putcharTwice; //Q3
    table['i'] = putcharTwice; //Q3
    table['o'] = putcharTwice; //Q3
    table['u'] = putcharTwice; //Q3

    while ((c = getchar()) != EOF) {
    table[c] (c); //Q4,
    }
    return 0;
}

Thanks a lot again!
 

10 More Discussions You Might Find Interesting

1. Programming

Problem with function which reutrns pointer to a value

i have a function: char *pcCityIdToCountryName(ADMIN_DB_DATA *pstHEader, unit uiCityID) this returns a pointer to CountryName if cityId is given. to retrieve countryname i give: char *CountryName; CountryName = pcCityIdToCountryName(..................); but when i compile it is giving :... (5 Replies)
Discussion started by: jazz
5 Replies

2. Programming

Pure Virtual Function in C++

Dear All, Here I want to know why we put =0 in case of pure virtual function, why not =1, =2 or any thing else Please send me answer any one as soon as possible. (1 Reply)
Discussion started by: krishna_sicsr
1 Replies

3. Programming

How to return void function pointer

Hello all im trying to build function that will return void function pointer what is mean is ( not working ) the main function void * myClass::getFunction(int type){ if(type==1) return &myClass::Test1; if(type==2) return &myClass::Test2; } void myClass::Test1(){... (1 Reply)
Discussion started by: umen
1 Replies

4. Programming

Function pointer to inline function ?

Hi. Problem: I have to parse the payload of a packet. The payload could be in Big Endian Format (network byte order) or little. That depends on a flag present in the header of the packet. Solution: A horrible solution could be to check for that flag everytime I have to read a field in the... (11 Replies)
Discussion started by: emitrax
11 Replies

5. Programming

Function Returning Pointer

Hi guys. how a functions such fdopen, ... can return pointer? are these functions use static memory(variables)? (6 Replies)
Discussion started by: majid.merkava
6 Replies

6. UNIX for Dummies Questions & Answers

Printing pointer address

How can I print the memory address of a pointer using printf (or any other STDOUT functions?). I see in Linux its %p but not in unix, help? thanks (5 Replies)
Discussion started by: perleo
5 Replies

7. Programming

structure pointer array as function parameters

if i create an array of pointers to a structure "struct node" as: struct node *r; and create "n" number of "linked lists" and assign it to the various struct pointers r using some function with a return type as structure pointer as: r=multiplty(.......) /*some parameters*/ is... (2 Replies)
Discussion started by: mscoder
2 Replies

8. Programming

Trivial doubt about C function pointer

Hi, In the below C code, #include <stdio.h> void print() { printf("Hello\n"); } int main() { void (*f)() = (void (*)()) print; f(); (*f)(); } I wonder, how the syntaxes "f()" and "(*f)()" are treated as same without any error? Is this an improvement or ANSI/ISO... (1 Reply)
Discussion started by: royalibrahim
1 Replies

9. UNIX for Dummies Questions & Answers

Counting vowels in string. "Comparison pointer-integer".

I'm trying to write a programme which scans strings to find how many vowels they contain. I get an error saying that I'm trying to compare a pointer and an integer inif(*v == scanme){. How can I overcome this ? Also, the programme seems to scan only the first word of a string e.g.: if I type "abc... (1 Reply)
Discussion started by: fakuse
1 Replies

10. Programming

Segmentation fault when I pass a char pointer to a function in C.

I am passing a char* to the function "reverse" and when I execute it with gdb I get: Program received signal SIGSEGV, Segmentation fault. 0x000000000040083b in reverse (s=0x400b2b "hello") at pointersExample.c:72 72 *q = *p; Attached is the source code. I do not understand why... (9 Replies)
Discussion started by: jose_spain
9 Replies
TACTIS(5)							File Formats Manual							 TACTIS(5)

NAME
TACTIS, tactis - A character encoding system (codeset) for Thai. DESCRIPTION
The TACTIS (Thai API Consortium/Thai Industrial Standard) codeset consists of the following two character sets: ASCII (ISO 646-1983) TIS 620-2533 These characters are 8-bit coded, ranging from 00 to FF. ASCII Characters In the TACTIS codeset, all ASCII characters are implemented in the form of single-byte, 7-bit characters; that is, the most significant bit (MSB) of ASCII characters is always set off. For more information, refer to ascii(5). TIS 620-2533 Characters The TIS 620-2533 character set includes 89 characters that are categorized as follows: Consonants: 44 Vowels: 18 total (5 leading vowels, 6 following vowels, 2 below vowels, and 5 above vowels) Tone marks: 4 Diacritics: 5 (4 above diacritics and 1 below diacritic) NonComposi- bles: 8 (1 nobreak space, 10 Thai digits, 6 Thai special characters, and 1 word separator) Note Thai digits are not recognized by the isdigit(), iswdigit(), isxdigit(), and iswxdigit(), isalnum(), and iswalnum() functions. Many applications make assumptions about how a digit character can be converted to its numeric equivalent. Changing the functions to rec- ognize Thai digits would break these applications. Code Ranges in the TACTIS Codeset In the TACTIS codeset, the most significant bit (MSB) of a byte is set on in codes for TIS 620-2533 characters. This differentiates TIS 620-2533 character code from ASCII character code. Following are the code ranges for each of the five categories of Thai characters in the codeset: -------------------------------------------------- Category Code Range (hex) -------------------------------------------------- Consonants A1 to CE Leading vowels E0 to E4 Normal following vowels D0, D2, D3, E5 Special following vowels C4, C6 Below vowels D8, D9 Above vowels D1, D4 to D7 Tone marks E8 to EB Above diacritics E7, EC to EE Below diacritics DA Nobreak space A0 Thai digits F0 to F9 Thai special characters CF, DF, E6, EF, FA, FB Word separator DC -------------------------------------------------- In TACTIS, the hexadecimal code points of TIS 620-2533 characters are as follows: A0 NO-BREAK SPACE C0 PO SAMPOW E0 SARA E A1 KO KAI C1 MO MA E1 SARA AE A2 KHO KHAI C2 YO YAK E2 SARA O A3 KHO KHUAT C3 RO RUA E3 SARA AI MAIMUAN A4 KHO KHWAI C4 RU E4 SARA AI MAIMALAI A5 KHO KHON C5 LO LING E5 LAKKHANGYAO A6 KHO RAKHANG C6 LU E6 MAIYAMOK A7 NGO NGU C7 WO WAEN E7 MAITAIKHU A8 CHO CHAN C8 SO SALA E8 MAI EK A9 CHO CHING C9 SO RUSI E9 MAI THO AA CHO CHANG CA SO SUA EA MAI TRIE AB SO SO CB HO HEEP EB MAI CHATTAWA AC CHO CHOE CC LO CHULA EC THANTHAKHAT AD YO YING CD O ANG ED NIKHANHIT AE DO CHADA CE HO NOKHUK EE YAMAKKAN AF TO PATAK CF PAIYANNOI EF FONGMAN B0 THO THO THAN D0 SARA A F0 THAI ZERO B1 THO NANGMONTHO D1 MAI HAN-AKAT F1 THAI ONE B2 THO PHOO THAO D2 SARA AA F2 THAI TWO B3 NOR NANE D3 SARA AM F3 THAI THREE B4 DOR DEK D4 SARA E F4 THAI FOUR B5 TO TAO D5 SARA EE F5 THAI FIVE B6 THO THUNG D6 SARA UR F6 THAI SIX B7 THO THAHAN D7 SARA UUR F7 THAI SEVEN B8 THO THONG D8 SARA U F8 THAI EIGHT B9 NO NU D9 SARA UU F9 THAI NINE BA BO BAIMAI DA PHINTHU FA ANGKHANKHU BB PO PLA DB FB KHOMUT BC PHO PERNG DC WORD SEPARATOR FC BD FO FA DD FD BE PO PAN DE FE BF FO FAN DF BAHT FF For more information on Thai characters, refer to Wototo(5). Fonts for TIS 620 2533 The operating system provides both screen and printer fonts for TIS 620 2533 characters. The following bitmap fonts reflect various sizes and typefaces for 75dpi and 100dpi display devices: -adecw-screen-medium-r-normal--14-140-75-75-p-70-tis620.2533-1 -adecw-screen-medium-r-normal--18-180-75-75-p-80-tis620.2533-1 -adecw- screen-medium-r-normal--24-240-75-75-p-120-tis620.2533-1 -adecw-screen-medium-r-normal--14-140-100-100-p-70-tis620.2533-1 -adecw-screen- medium-r-normal--18-180-100-100-p-80-tis620.2533-1 -adecw-screen-medium-r-normal--24-240-100-100-p-120-tis620.2533-1 The operating system provides the following Thai fonts for PostScript printers: AngsanaUPC-Bold AngsanaUPC-BoldItalic AngsanaUPC-Italic AngsanaUPC-Light CordiaUPC-Bold CordiaUPC-BoldItalic CordiaUPC-Italic CordiaUPC-Light EucrosiaUPC-Bold EucrosiaUPC-BoldItalic EucrosiaUPC- Italic EucrosiaUPC-Light FreesiaUPC-Bold FreesiaUPC-BoldItalic FreesiaUPC-Italic FreesiaUPC-Light IrisUPC-Bold IrisUPC-BoldItalic IrisUPC- Italic IrisUPC-Light JasmineUPC-Bold JasmineUPC-BoldItalic JasmineUPC-Italic JasmineUPC-Light KodchiangUPC-Bold KodchiangUPC-BoldItalic KodchiangUPC-Italic KodchiangUPC-Light LilyUPC-Bold LilyUPC-BoldItalic LilyUPC-Italic LilyUPC-Light WaterlilyUPC-Bold WaterlilyUPC- BoldItalic WaterlilyUPC-Italic WaterlilyUPC-Light YuccaUPC-Bold YuccaUPC-BoldItalic YuccaUPC-Italic YuccaUPC-Light For general information on printing Asian language text, refer to i18n_printing(5). Codeset Conversion The following converter pairs are available for converting data between TACTIS and other encoding formats. Refer to iconv_intro(5) for an introduction to codeset conversion. For more information about the other codeset for which TACTIS is the input or output, see the reference page specified in the list item. cp874_TACTIS, TACTIS_cp874 Converting from and to PC code page 874: code_page(5) UCS-2_TACTIS, TACTIS_UCS-2 Converting from and to UCS-2: Unicode(5) UCS-4_TACTIS, TACTIS_UCS-4 Converting from and to UCS-4: Unicode(5) UTF-8_TACTIS, TACTIS_UTF-8 Converting from and to UTF-8: Unicode(5) SEE ALSO
Commands: locale(1) Others: code_page(5), ascii(5), i18n_intro(5), i18n_printing(5), iconv_intro(5), Thai(5), Unicode(5), Wototo(5) TACTIS(5)
All times are GMT -4. The time now is 03:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy