目錄:git
標題1:大學算法
void strcat (char *s, char *t){ while ( *s ) s++; while (*s++ = *t++); } /* t複製給s */ void strcpy (char *s, char *t){ while (*s++ = *t++); } /* 字符串長度 */ int strlen(char *s){ char *p = s; while ( *p ) p++; return p-s; }
標題2:工做ide
/* atof(): 把字符串轉換爲浮點數 */ double atof(char s[]){ double val, power; int i, sign; for (i=0; isspace(s[i]); i++) //跳過空格 ; sign = (s[i] == '-') ? -1 : 1; if (s[i] == '+' || s[i] == '-') i++; for (val = 0.0; isdigit(s[i]); i++) val = 10.0 * val + (s[i] - '0'); if (s[i] == '.') i++; for (power=1.0; isdigit(s[i]); i++){ val = 10.0 * val + (s[i] - '0'); power *= 10.0; } return sign * val / power; } /* 計算小數的另一種算法 for (power = 10.0; isdigit(s[i]); i++){ val = val + (s[i] - '0') / power; power *= 10.0; } */