[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Read UTF-8 characters from text files

From: Santiago Higuera
Subject: Re: Read UTF-8 characters from text files
Date: Fri, 8 Dec 2017 21:39:24 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0


I have prepared a sample file with utf-8 characters to explain my problem using fscanf(fid,'%s'). The file can be downloaded from [1].

If I use fread(), it reads the correct byte value for extended characters, but if I use fscanf(), I receive the message 'warning: range error for conversion to character value', and the extended code characters are not read in the result string. I can read the correct line if I use fgets() or fgetl(), but I need single words to process the file and the same problem occurs with sscanf(), if I try to read the words from a string variable.

I checked the problem in Matlab, and I have verified the Matlab can read the correct characters from string with utf8 extended codes. I have spent a lot of time googling for the solution, but I have not found anything that solves the problem.

Can you help me? Is there any workaround to solve the problem. I'm teaching Octave to my students and we need to process a lot of statistics files in Spanish language, that have a lot of this kind of characters. In my University, there are free Matlab licences for the students and professors, but I always recommend to my students the use of Octave.  I wouldn't like to surrender to the use of Matlab due to this problem.

Thanks in advance.


Santiago Higuera


El 07/12/17 a las 00:18, Santiago Higuera escribió:

I'm trying to read some text files with Spanish characters, as ñ, ó and others.

I don't know how to do it. I have tried with fscanf('%s'), but I get a warning message:  'warning: range error for conversion to character value'

Can you help me?

Thanks, regards

Santiago Higuera

reply via email to

[Prev in Thread] Current Thread [Next in Thread]