我是 C 语言的初学者。我不明白函数定义部分。“strchr(s,oldch)”有什么作用?我正在尝试将其转换为 ctypes 程序。
#include <stdio.h>
#include <string.h>
#include <math.h>
/* Replace och with nch in s and return the number of replacements */
extern int replace(char *s, char och, char nch);
/* Replace a character in a string */
int replace(char *s, char oldch, char newch) {
int nrep = 0;
while (s = strchr(s,oldch)) {
*(s++) = newch;
nrep++;
}
return nrep;
}
/* Test the replace() function */
{
char s[] = "Skipping along unaware of the unspeakable peril.";
int nrep;
nrep = replace(s,' ','-');
printf("%d\n", nrep);
printf("%s\n",s);
}
是什么while (s = strchr(s,oldch))
意思?它做什么工作?其他方式怎么写?谁能解释一下?