C Primer Plusからコードのスニペットを読み、理解しようとしました*find = '\0';
#include <stdio.h>
#include <string.h>
char *s_gets(char *st, int n);
struct book {
char title[40];
char author[40];
float value;
}
int main(void) {
...
}
char *s_gets(char *st, int n) {
char *ret_val;
char *find;
ret_val = fgets(st, n, stdin);
if (ret_val) {
find = strchr(st, '\n'); //look for newline
if (find) // if address is not null
*find = '\0'; //place a null character there
else
while (getchar() != '\n')
continue; //dispose rest of line
}
return ret_val;
}
どのような目的find = strchr(st, '\n');
で従うべきか*find = '\0';
検索strchr
しましたが、機能については理解できましたが、奇妙な名前であることがわかりました。名前のstrchr
由来はstringcharacter
?