non ascii chracter problem

Discussion in 'C Programming' started by Burak, Oct 25, 2007.

  1. Burak

    Burak Guest

    i'll try to explain my problem shortly...

    char wrt[50];
    char word[50];

    strcpy(wrt,"şç");
    printf("%s\n",wrt);
    //i get ■ as output

    gets(word); //i will write şç
    printf("%s \n",word);
    //output of this is correct,şç

    How can i solve this?
    Any suggestions?
     
    Burak, Oct 25, 2007
    #1
    1. Advertising

  2. Burak

    CBFalconer Guest

    Burak wrote:
    >
    > i'll try to explain my problem shortly...
    >
    > char wrt[50];
    > char word[50];
    >
    > strcpy(wrt,"şç");
    > printf("%s\n",wrt);
    > //i get ■ as output
    >
    > gets(word); //i will write şç
    > printf("%s \n",word);
    > //output of this is correct,şç
    >
    > How can i solve this?
    > Any suggestions?


    Never, ever, under any circumstances, use gets(). You can get a
    replacement (with equal convenience that can be used safely) in
    ggets(). You will find it at:

    <http://cbfalconer.home.att.net/download/>

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Oct 25, 2007
    #2
    1. Advertising

  3. Burak

    Richard Guest

    CBFalconer <> writes:

    > Burak wrote:
    >>
    >> i'll try to explain my problem shortly...
    >>
    >> char wrt[50];
    >> char word[50];
    >>
    >> strcpy(wrt,"şç");
    >> printf("%s\n",wrt);
    >> //i get ■ as output
    >>
    >> gets(word); //i will write şç
    >> printf("%s \n",word);
    >> //output of this is correct,şç
    >>
    >> How can i solve this?
    >> Any suggestions?

    >
    > Never, ever, under any circumstances, use gets(). You can get a
    > replacement (with equal convenience that can be used safely) in
    > ggets(). You will find it at:
    >
    > <http://cbfalconer.home.att.net/download/>
    >
    > --
    > Chuck F (cbfalconer at maineline dot net)
    > Available for consulting/temporary embedded and systems.
    > <http://cbfalconer.home.att.net>


    gets can be and is used perfectly safely in many controlled
    situations. Advisable to use it? Probably not. ggets has its own issues
    IMO.
     
    Richard, Oct 25, 2007
    #3
  4. Burak

    Keith Willis Guest

    On Thu, 25 Oct 2007 16:56:10 +0200, Richard <> wrote:

    >CBFalconer <> writes:
    >
    >> Never, ever, under any circumstances, use gets(). You can get a
    >> replacement (with equal convenience that can be used safely) in
    >> ggets(). You will find it at:
    >>

    >gets can be and is used perfectly safely in many controlled
    >situations. Advisable to use it? Probably not. ggets has its own issues
    >IMO.


    I'm puzzled.
    1. How could gets be used "perfectly safely"?
    2. What on earth is wrong with fgets()? [f]ggets makes me free memory
    that it allocated, whereas with fgets, I can sort out my own
    allocation as and when (and however) I want to.
    --
    PGP key ID 0xEB7180EC
     
    Keith Willis, Oct 25, 2007
    #4
  5. Burak

    santosh Guest

    Keith Willis wrote:

    > On Thu, 25 Oct 2007 16:56:10 +0200, Richard <> wrote:
    >
    >>CBFalconer <> writes:
    >>
    >>> Never, ever, under any circumstances, use gets(). You can get a
    >>> replacement (with equal convenience that can be used safely) in
    >>> ggets(). You will find it at:
    >>>

    >>gets can be and is used perfectly safely in many controlled
    >>situations. Advisable to use it? Probably not. ggets has its own
    >>issues IMO.

    >
    > I'm puzzled.
    > 1. How could gets be used "perfectly safely"?


    If you can completely control stdin.

    <snip>
     
    santosh, Oct 25, 2007
    #5
  6. Burak

    Richard Guest

    Keith Willis <> writes:

    > On Thu, 25 Oct 2007 16:56:10 +0200, Richard <> wrote:
    >
    >>CBFalconer <> writes:
    >>
    >>> Never, ever, under any circumstances, use gets(). You can get a
    >>> replacement (with equal convenience that can be used safely) in
    >>> ggets(). You will find it at:
    >>>

    >>gets can be and is used perfectly safely in many controlled
    >>situations. Advisable to use it? Probably not. ggets has its own issues
    >>IMO.

    >
    > I'm puzzled.
    > 1. How could gets be used "perfectly safely"?


    if you know the problems with it in a badly controlled environment then
    it doesn't take a leap of faith to figure out how it can be used safely
    - when you totally control the input stream e.g another process.

    > 2. What on earth is wrong with fgets()? [f]ggets makes me free memory
    > that it allocated, whereas with fgets, I can sort out my own
    > allocation as and when (and however) I want to.


    Nothing is wrong with fgets. Did anyone say there is?
     
    Richard, Oct 25, 2007
    #6
  7. Burak <> writes:

    > i'll try to explain my problem shortly...
    >
    > char wrt[50];
    > char word[50];
    >
    > strcpy(wrt,"şç");
    > printf("%s\n",wrt);
    > //i get ■ as output
    >
    > gets(word); //i will write şç
    > printf("%s \n",word);
    > //output of this is correct,şç
    >
    > How can i solve this?


    These things are very hard to debug over Usenet. I can not be sure of
    what you have in your C file or in your output since simply copying
    into a message can change the character encoding.

    > Any suggestions?


    Best guess: the program you use to type in your C code uses a
    different character encoding from the terminal/console you run it on.
    To get a better-informed guess, ask in a group that knows about your
    development environment.

    --
    Ben.
     
    Ben Bacarisse, Oct 25, 2007
    #7
  8. Burak

    CBFalconer Guest

    Keith Willis wrote:
    > Richard <> wrote:
    >> CBFalconer <> writes:
    >>
    >>> Never, ever, under any circumstances, use gets(). You can get a
    >>> replacement (with equal convenience that can be used safely) in
    >>> ggets(). You will find it at:

    >>
    >> gets can be and is used perfectly safely in many controlled
    >> situations. Advisable to use it? Probably not. ggets has its own
    >> issues IMO.

    >
    > I'm puzzled.
    > 1. How could gets be used "perfectly safely"?
    > 2. What on earth is wrong with fgets()? [f]ggets makes me free
    > memory that it allocated, whereas with fgets, I can sort out
    > my own allocation as and when (and however) I want to.


    I did NOT say gets can be used safely. I recommended ggets. Note
    the extra g. There is nothing wrong with fgets if you can put up
    with its nuisances, such as not knowing whether the line is
    complete without checking for a terminal '\n'. In many cases the
    first thing you are going to do with an incoming line is allocate
    memory to hold it, and tuck it away. No need with ggets.

    A routine is only useful if it fits your practice. The ggets
    package includes usage examples.

    Incidentally, "Richard <>" is plonked here, because
    his recommendations are generally idiotic. This includes his
    quoted advice above.

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>


    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Oct 25, 2007
    #8
  9. Burak

    Richard Bos Guest

    Richard <> wrote:

    > CBFalconer <> writes:
    >
    > > Burak wrote:


    > >> gets(word); //i will write şç


    > > Never, ever, under any circumstances, use gets(). You can get a
    > > replacement (with equal convenience that can be used safely) in
    > > ggets(). You will find it at:


    > gets can be and is used perfectly safely in many controlled situations.


    Not legally in states where bondage gear falls under the local obscenity
    laws.

    Richard
     
    Richard Bos, Oct 26, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TOXiC
    Replies:
    5
    Views:
    1,325
    TOXiC
    Jan 31, 2007
  2. James O'Brien
    Replies:
    3
    Views:
    305
    Ben Morrow
    Mar 5, 2004
  3. Jochen Lehmeier

    DBD::Oracle, Unicode, non-UTF8-non-ASCII strings

    Jochen Lehmeier, Jul 23, 2009, in forum: Perl Misc
    Replies:
    0
    Views:
    448
    Jochen Lehmeier
    Jul 23, 2009
  4. bruce
    Replies:
    38
    Views:
    322
    Mark Lawrence
    Nov 1, 2013
  5. MRAB
    Replies:
    0
    Views:
    116
Loading...

Share This Page