Simple Sand Samples |
C言語 > 文字列を一文字毎に分割する
split-char.c
#include <stdio.h> int main() { char str[] = "HELLO"; char *p=str; while(1){ if(*p == '\x0')break; printf("[%c]\n",*p++); } return 0; }
$ gcc split-char.c
$ ./a.out
[H]
[E]
[L]
[L]
[O]
$
$ ./a.out
[H]
[E]
[L]
[L]
[O]
$
* 確認環境 Debian Linux(Wheezy)