I am a beginner to C language. I dont understand the function defintion part. What does "strchr(s,oldch)" do? I am trying to convert it into ctypes program.
#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);
}
what does while (s = strchr(s,oldch))
mean? what work it does ?
How to write it in other ways?
Can anyone explain it ?