Back to Type Challenges

README.Ja

questions/00147-hard-c-printf-parser/README.ja.md

latest1.9 KB
Original Source
<!--info-header-start--><h1>C-printf Parser </h1><blockquote><p>by Pig Fang <a href="https://github.com/g-plane" target="_blank">@g-plane</a></p></blockquote><p><a href="https://tsch.js.org/147/play/ja" target="_blank"></a> &nbsp;&nbsp;&nbsp;<a href="./README.md" target="_blank"></a> </p><!--info-header-end-->

C 言語にはprintfという関数があり、以下のようにフォーマットして出力してくれます。

c
printf("The result is %d.", 42);

この課題では、入力値の文字列をパースして%d%fのようなフォーマットのプレースホルダーを抜き出します。 例えば、もし入力文字列が"The result is %d"であるなら、パースした結果は['dec']というタプルになります。

マッピングは以下となります。

typescript
type ControlsMap = {
  c: 'char';
  s: 'string';
  d: 'dec';
  o: 'oct';
  h: 'hex';
  f: 'float';
  p: 'pointer';
};
<!--info-footer-start-->

<a href="../../README.ja.md" target="_blank"></a> <a href="https://tsch.js.org/147/answer/ja" target="_blank"></a> <a href="https://tsch.js.org/147/solutions" target="_blank"></a> <!--info-footer-end-->