The example program of C on point

简介:
计划一:
#include<stdio.h>

#define     N_VALUES        5

int main( void )
{
    float values[N_VALUES];
    float *vp;

    for( vp = &values[0]; vp < &values[N_VALUES]; )
        *vp++ = 0;

    for( vp = &values[N_VALUES]; vp > &values[0]; )
        *--vp =0;

    for( vp = &values[N_VALUES]; vp >= &values[0]; vp-- )
        *vp = 0;
    //不建议使用 数组下标越界
    //标准同意指向数组元素的指针与最后一个元素内存位置的指针进行比較
    //不同意第一个元素和之前内存位置的指针比較

    return 0;
}
程序二:
/*
**Programe6.1
**计算一个字符串的函数
*/
#include<stdio.h>
int strlen(char *string)
{
    int lenth=0;
    while(*string++!='\0')
        lenth++;
    return lenth;
}
int main(void)
{
    char *string = NULL;
    string="zxczxc";
    printf("%d",strlen(string));
    return 0;
}

自己写库函数 真好玩~

程序三:

/*
**Programe6.2 在一组字符串中查找 版本号1
**给定一个指向以NULL结尾的指针列表的指针。在列表的字符串中查找一个特定的字符。
*/

#include<stdio.h>
#define     TRUE    1
#define     FALSE   0

int find_char( char **strings, char value )
{
    char *string;   //我们当前源字符串

    /*
    **对于列表中每一个字符串的处理
    */
    while( ( string = *strings++ ) !=NULL )
    {
        /*
        **遍历每一个字符串 是否为目标字符串
        */
        while( *string != '\0' )
        {
            if( *string ++ == value)
                return TRUE;
        }
    }
    return FALSE;
}
int main( void )
{
    char* str[3][10]={"sdf","sdfdhf","fdghdf"};
    int result = find_char(str[0],'x');
    printf("%d",result);
    return 0;
}

一个指向数组确实无法使用   瞎蒙 实际测试的~





本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5035779.html如需转载请自行联系原作者


相关文章
|
2月前
|
Shell 网络安全 C语言
Program Misuse(2)
Program Misuse(2)
40 6
|
3月前
|
PyTorch 算法框架/工具
The “freeze_support()“ line can be omitted if the program is not going to be frozen
The “freeze_support()“ line can be omitted if the program is not going to be frozen
23 1
Why expand does not work for complex note
Why expand does not work for complex note? Created by Wang, Jerry, last modified on Jan 12, 2015
Why expand does not work for complex note
CL_ABAP_COMPILER - get ID - double click on local variable
CL_ABAP_COMPILER - get ID - double click on local variable
135 0
CL_ABAP_COMPILER - get ID - double click on local variable
Navigation execution entry point
Created by Jerry Wang, last modified on Jan 18, 2015
Navigation execution entry point
|
网络协议 安全
|
监控 安全 网络安全
|
监控 安全 网络安全
|
安全 网络安全