我从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
?