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


你可能感兴趣的:(C++,c,test)