Sponsored Content
Top Forums Programming How to read extended ASCII characters from stdin? Post 302932095 by sanzee007 on Monday 19th of January 2015 04:16:12 AM
Old 01-19-2015
In the below code I tried to read the entered text in a buffer and showing the length of data read from stdin.

Code:
#include <stdio.h>
#include <wchar.h>
#include <stdlib.h>
#include <locale.h>

#define BUFSIZE  256

wchar_t* readFromStdin(const wchar_t *);

wchar_t m_buf[BUFSIZE];

int main()
{
        const wchar_t *pwch;
        char *pbuf = NULL;
        setlocale(LC_ALL, "");
        printf("Enter the word having extended characters:");
        pwch = readFromStdin(L"Word: ");
        printf("The Wide char string is: %S\n", pwch);
        wcstombs(pbuf, pwch, wcslen(pwch)+1); // I have to convert the wchar_t data to char* for further processing

return 0;
}

wchar_t *readFromStdin(const wchar_t *ptr) // Though this function is not doing what its name suggests
{
        unsigned int size;
        scanf("%ls",m_buf);
        size = wcslen(m_buf);

        printf("Size of buf = %d\n", size);
        return (m_buf);

}

Whether this code will properly read any word having extended ascii characters and be able to show the desired length of the word.?

Thanks,
Moderator's Comments:
Mod Comment Please use CODE tags (not ICODE tags) for multi-line input, output, and code samples.

Last edited by Don Cragun; 01-19-2015 at 05:24 AM.. Reason: Change ICODE tags to CODE tags for multi-line data.
 

10 More Discussions You Might Find Interesting

1. Programming

Extended ascii

Hi all, I would like to change the extended ascii code ( 128 - 255). I tried to change LC_ALL and LANG in current session ( values from locale -a) and for no good. Thanks. (0 Replies)
Discussion started by: avis
0 Replies

2. Shell Programming and Scripting

extended ascii problem

hi i would like to check text files if they contain extended ascii characters within or not. i really dont have any idea how to start your kind help would be very much appreciated thanks. (7 Replies)
Discussion started by: smooth
7 Replies

3. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

4. Shell Programming and Scripting

convert ascii values into ascii characters

Hi gurus, I have a file in unix with ascii values. I need to convert all the ascii values in the file to ascii characters. File contains nearly 20000 records with ascii values. (10 Replies)
Discussion started by: sandeeppvk
10 Replies

5. AIX

Printing extended ASCII

Hi All, I'm trying to send extended ascii characters to my HP2055 as part of PCL printer control codes. What I want to do is select a bar code font, print the bar code and reset the printer to the default font. Selecting the bar code font works good. Printing the bar code goes almost ok too. ... (5 Replies)
Discussion started by: petervg
5 Replies

6. Shell Programming and Scripting

Identify extended ascii characters in a file

Hi, Is there a way to identify the lines in a file having extended ascii characters and display the same? For instance I have a file abc.txt having below data aaa|bbb|111|This is first line aaa|bbb|222|This is secõnd line aaa|bbb|333|This is third line aaa|bbb|444|This is foùrth line... (3 Replies)
Discussion started by: decci_7
3 Replies

7. Shell Programming and Scripting

Search and Replace Extended Ascii Characters

We are getting extended Ascii characters in the input file and my requirement is to search and replace them with a space. I am using the following command LANG=C sed -e 's// /g' It is doing a good job, but in some cases it is replacing the extended characters with two spaces. So my input... (12 Replies)
Discussion started by: ysvsr1
12 Replies

8. Shell Programming and Scripting

Removal Extended ASCII using awk

Hi All, I am trying to remove (SELECTIVE - passed as argument) Extended ASCII using Awk based on adhoc basis. Can you please let me know how to do it. I have to implement this using awk only. Thanks & Regads (14 Replies)
Discussion started by: tostay2003
14 Replies

9. Shell Programming and Scripting

Extended ASCII Characters keep on getting reintroduced to text files

I am working with a log file that I am trying to clean up by removing non-English ASCII characters. I am using Bash via Cygwin on Windows. Before I start I set: export LC_ALL=C I clean it up by removing all non-English ASCII characters with the following command; grep -v $''... (4 Replies)
Discussion started by: lewk
4 Replies

10. UNIX for Beginners Questions & Answers

Print byte position of extended ascii character

Hello, I am on AIX. When I encounter extended ascii characters and special characters on a file I need to print.. Byte position, actual character and line number. Is there a simple command that can give me the above result ? Thanks in advance (38 Replies)
Discussion started by: rosebud123
38 Replies
WMEMCHR(3)						   BSD Library Functions Manual 						WMEMCHR(3)

NAME
wmemchr, wmemcmp, wmemcpy, wmemmove, wmemset, wcpcpy, wcpncpy, wcscasecmp, wcscat, wcschr, wcscmp, wcscpy, wcscspn, wcsdup, wcslcat, wcslcpy, wcslen, wcsncasecmp, wcsncat, wcsncmp, wcsncpy, wcsnlen, wcspbrk, wcsrchr, wcsspn, wcsstr -- wide character string manipulation operations LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <wchar.h> wchar_t * wmemchr(const wchar_t *s, wchar_t c, size_t n); int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n); wchar_t * wmemcpy(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n); wchar_t * wmemmove(wchar_t *s1, const wchar_t *s2, size_t n); wchar_t * wmemset(wchar_t *s, wchar_t c, size_t n); wchar_t * wcpcpy(wchar_t *s1, wchar_t *s2); wchar_t * wcpncpy(wchar_t *s1, wchar_t *s2, size_t n); int wcscasecmp(const wchar_t *s1, const wchar_t *s2); wchar_t * wcscat(wchar_t * restrict s1, const wchar_t * restrict s2); wchar_t * wcschr(const wchar_t *s, wchar_t c); int wcscmp(const wchar_t *s1, const wchar_t *s2); wchar_t * wcscpy(wchar_t * restrict s1, const wchar_t * restrict s2); size_t wcscspn(const wchar_t *s1, const wchar_t *s2); wchar_t * wcsdup(const wchar_t *s); size_t wcslcat(wchar_t *s1, const wchar_t *s2, size_t n); size_t wcslcpy(wchar_t *s1, const wchar_t *s2, size_t n); size_t wcslen(const wchar_t *s); int wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n); wchar_t * wcsncat(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n); int wcsncmp(const wchar_t *s1, const wchar_t * s2, size_t n); wchar_t * wcsncpy(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n); size_t wcsnlen(const wchar_t *s, size_t maxlen); wchar_t * wcspbrk(const wchar_t *s1, const wchar_t *s2); wchar_t * wcsrchr(const wchar_t *s, wchar_t c); size_t wcsspn(const wchar_t *s1, const wchar_t *s2); wchar_t * wcsstr(const wchar_t * restrict s1, const wchar_t * restrict s2); DESCRIPTION
The functions implement string manipulation operations over wide character strings. For a detailed description, refer to documents for the respective single-byte counterpart, such as memchr(3). SEE ALSO
memchr(3), memcmp(3), memcpy(3), memmove(3), memset(3), stpcpy(3), stpncpy(3), strcasecmp(3), strcat(3), strchr(3), strcmp(3), strcpy(3), strcspn(3), strdup(3), strlcat(3), strlcpy(3), strlen(3), strncat(3), strncmp(3), strncpy(3), strnlen(3), strpbrk(3), strrchr(3), strspn(3), strstr(3) STANDARDS
These functions conform to ISO/IEC 9899:1999 (``ISO C99''), with the exception of wcpcpy(), wcpncpy(), wcscasecmp(), wcsdup(), wcsncasecmp(), and wcsnlen(), which conform to IEEE Std 1003.1-2008 (``POSIX.1''); and wcslcat() and wcslcpy(), which are extensions. BSD
March 4, 2009 BSD
All times are GMT -4. The time now is 11:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy