求字符串长度StringLength();


// StringLength2.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
int StringLength(char str[])
{
    int i=-1;
    while(str[++i])
        ;
    return i;
}

int _tmain(int argc, _TCHAR* argv[])
{
    char s[128];
    printf("input sth.:");
    scanf_s("%s",&s,sizeof(s));
    printf("字符总数为:%d\n",StringLength(s));
    return 0;
}

反汇编:

用指针快,int类型读入和char类型读入不一样。int比char要快。

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM