blog/content/post/2008/06/20/2008-06-20-00000953.md

33 lines
2.0 KiB
Markdown

---
title: 文字列の先頭から走査して半角空白ではない最初の要素のポインタを返す
author: kazu634
date: 2008-06-20
url: /2008/06/20/_1025/
wordtwit_post_info:
- 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:4091;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
categories:
- C
- Programming
---
<div class="section">
<pre class="syntax-highlight">
<span class="synPreProc">#include </span><span class="synConstant">&#60;stdio.h&#62;</span>
<span class="synComment">/* 文字列のポインタを引数として */</span>
<span class="synComment">/* 半角空白ではない先頭文字列へのポインタを返す関数 */</span>
<span class="synType">char</span> *get_char_ptr(<span class="synType">char</span> *char_ptr){
<span class="synComment">/* 文字列の要素が空白である間、インクリメント */</span>
<span class="synStatement">while</span> (*char_ptr == <span class="synConstant">' '</span>) char_ptr++;
<span class="synStatement">return</span>(char_ptr);
}
<span class="synType">int</span> main(<span class="synType">void</span>){
<span class="synType">char</span> tmp[<span class="synConstant">30</span>] = <span class="synConstant">&#34; abcd0123456789&#34;</span>;
<span class="synType">char</span> search;
printf (<span class="synConstant">&#34;Searching String: </span><span class="synSpecial">%s</span><span class="synConstant">&#34;</span>, tmp);
printf (<span class="synConstant">&#34;</span><span class="synSpecial">\n</span><span class="synConstant">&#34;</span>);
<span class="synComment">/* 先頭要素のポインタが指すものを取得するよ */</span>
search = *(get_char_ptr(tmp));
printf (<span class="synConstant">&#34;</span><span class="synSpecial">%c\n</span><span class="synConstant">&#34;</span>, search);
}
</pre>
</div>