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
libssh2_channel_handle_extended_data2(3)			  libssh2 manual			  libssh2_channel_handle_extended_data2(3)

NAME
libssh2_channel_handle_extended_data2 - set extended data handling mode SYNOPSIS
#include <libssh2.h> int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel, int ignore_mode); DESCRIPTION
channel - Active channel stream to change extended data handling on. ignore_mode - One of the three LIBSSH2_CHANNEL_EXTENDED_DATA_* Constants. LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL: Queue extended data for eventual reading LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE: Treat extended data and ordinary data the same. Merge all substreams such that calls to libssh2_chan- nel_read(3) will pull from all substreams on a first-in/first-out basis. LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE: Discard all extended data as it arrives. Change how a channel deals with extended data packets. By default all extended data is queued until read by libssh2_channel_read_ex(3) RETURN VALUE
Return 0 on success or LIBSSH2_ERROR_EAGAIN when it would otherwise block. SEE ALSO
libssh2_channel_handle_extended_data(3) libssh2_channel_read_ex(3) libssh2 0.15 1 Jun 2007 libssh2_channel_handle_extended_data2(3)
All times are GMT -4. The time now is 01:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy