#include #define MAXCHAR 10 /* 10 文字分ってやつ */ void con_gets(char* str, int buf_size); void main () { char str[MAXCHAR + 1]; /* ※文字列なので '\0' の分も加味する */ int end_flg = 0; while (end_flg == 0) { printf("文字列を入力して下さい:"); con_gets(str, sizeof(str)); if (*str == '@' && *(str + 1) == '\0') { /* バッファの 1 番目が '@' と 2 番目が '\0' で終了 */ end_flg = 1; } else { printf("入力された文字列:%s\n", str); } } printf("*** プログラムを終了します ***\n"); } void con_gets(char* str, int buf_size) { int cnt = 0; char ch; while ((ch = getchar()) != '\n') { /* '\n' が出現するまで繰り返し */ if (cnt < buf_size - 1) { *(str + cnt) = ch; cnt = cnt + 1; } } *(str + cnt) = '\0'; }