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

Re: Backspace 2bytes character



井上です。

KIRIAKE Masanori <seiken@...> writes:

> '{'と'}'を探してその間を文字にする?で、その文字列長が2バイトを越えてい
> たら捨てる?
> 
> うむ、美しくない。

SJISの2バイト目に}がくることがないのであれば、以下でよいようです。
毎回bufの2バイト目以降を0にする必要がありますが。

scanf()って置くが深いんですよね。

#include <stdio.h>

int main()
{
  char buf[3] = {0, 0, 0};
  scanf("l {%2[^}]}", buf);
  printf("%s\n", buf);
  return 0;
}

-- 
                    Koichi Inoue, ARGV
                    E-Mail: inoue@...
                    ICQ UIN: 74900690