for test

目錄:


標題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:工作

/* 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;
    }
*/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章