#### Can someone help explain what this C algorithm is doing?

``````int f(char *s) {
char *p = s;
int c = 1;
while (*p == ’ ’)
++p;
while (*p != ’\0’) {
if ( *p < ’0’ || *p > ’9’ ) {
printf("Error!\n"); return 0;
}
++p; }
for (--p; p >= s; --p) {
if (*p == ’ ’) *p = ’0’;
*p += c;
if (*p > ’9’) {
*p = ’0’; c = 1;
} else
c = 0;
if (c == 0) break;
}
if (c != 0) {
printf("Error!\n");
return 0;
}
return 1; }
``````
1 个回复
``````// return an integer given a character pointer, a string.
int f(char *s) {
// Set current position to start of string
char *p = s;
// Initialise carry flag to '1'.
int c = 1;
// Move position past leading spaces
while (*p == ’ ’)
++p;
// Check remaining characters are in the set {'0','1',..,'9'}
while (*p != ’\0’) {
// If they are not, return with an error
if ( *p < ’0’ || *p > ’9’ ) {
printf("Error!\n"); return 0;
}
++p; }
// Now counting back from the end of the string
for (--p; p >= s; --p) {
// Turn a space into a '0';
if (*p == ’ ’) *p = ’0’;
// Increment the digit by the value of the carry; one or zero
*p += c;
// This might cause a further carry, capture that
if (*p > ’9’) {
*p = ’0’; c = 1;
} else
c = 0;
// if no carry, break, else keep on with the carry
if (c == 0) break;
}
// If still carrying passed the end of the space, call an error.
if (c != 0) {
printf("Error!\n");
return 0;
}
return 1; }
``````

2 有人可以解释此REGEX在做什么吗？ [重复]

2019-10-18 12:46:37 1 55   regex
3 有人可以解释这条线在做什么

2018-07-14 15:52:32 3 50   reactjs
4 有人可以解释这段代码在做什么吗？

9 有人可以向我解释这个php代码在做什么吗？