• C++二级指针第三种内存模型


    #include "stdio.h"
    #include "stdlib.h"
    #include "string.h"
    void main()
    {
        int i = 0, j = 0;
        char buf[100];
        char **myarray = (char **)malloc(10*sizeof(char*)); //int array[10]
        if (myarray == NULL)
        {
            return;
        }
        for (i=0; i<10; i++)
        {
            myarray[i] = (char *)malloc(100*sizeof(char)); //char buf[100];
            if (myarray[i]  == NULL)
            {
                printf("ddddde
    ");
                return;
            }
            sprintf(myarray[i],"%d%d%d ", i, i, i);
        }
    
        //第三种内存模型打印 
        printf("排序之前
    ");
        for (i=0; i<10; i++)
        {
            printf("%s
    ", myarray[i]);
        }
    
        //排序
        for (i=0; i<10; i++)
        {
            for (j=i+1; j<10; j++)
            {
                if (strcmp(myarray[i], myarray[j]) < 0)
                {
                    strcpy(buf, myarray[i]);
                    strcpy(myarray[i], myarray[j]);
                    strcpy(myarray[j], buf);
                }
            }
        }
    
        //第三种内存模型打印
        printf("排序之后
    ");
        for (i=0; i<10; i++)
        {
            printf("%s
    ", myarray[i]);
        }
    
        for (i=0; i<10; i++)
        {
            free(myarray[i] );
        }
        if (myarray != NULL) 
        {
            free(myarray);
        }
    
        system("pause");
    }
    #include "stdio.h"
    #include "stdlib.h"
    #include "string.h"
    int    printfArr33(char **ArrayStr, int iNum)
    {
        int i = 0;
        for (i=0; i<iNum; i++)
        {
            printf("%s 
    ", ArrayStr[i]);
        }
        return 0;
    }
    
    int sortArrayStr03(char **ArrayStr, int iNum)
    {
        int i = 0, j = 0;
        char *tmp = NULL;
        //排序
    
        for (i=0; i<iNum; i++)
        {
            for (j=i+1; j<iNum; j++)
            {
                if (strcmp(ArrayStr[i],ArrayStr[j]) < 0)
                {
                    tmp = ArrayStr[i];
                    ArrayStr[i] = ArrayStr[j];
                    ArrayStr[j] = tmp;
                }
            }
        }
        return 0;
    }
    
    void main()
    {
        int i = 0, j = 0;
        char buf[100];
        char **myarray = (char **)malloc(10*sizeof(char*)); //int array[10]
        if (myarray == NULL)
        {
            return;
        }
        for (i=0; i<10; i++)
        {
            myarray[i] = (char *)malloc(100*sizeof(char)); //char buf[100];
            if (myarray[i]  == NULL)
            {
                printf("ddddde
    ");
                return;
            }
            sprintf(myarray[i],"%d%d%d ", i, i, i);
        }
    
        //第三种内存模型打印 
        printf("排序之前
    ");
        printfArr33(myarray, 10);
    
        sortArrayStr03(myarray, 10);
    
        //第三种内存模型打印
        printf("排序之后
    ");
        printfArr33(myarray, 10);
    
        for (i=0; i<10; i++)
        {
            free(myarray[i] );
        }
        if (myarray != NULL) 
        {
            free(myarray);
        }
    
        system("pause");
    }
  • 相关阅读:
    JAVA WEBSERVICE服务端&客户端的配置及调用(基于JDK)
    An internal error occurred during: "Launching New_configuration"
    Android 创建虚拟机时“提示no system images installed for this target”
    [转] 传说中的WCF(2):服务协定的那些事儿
    [转] 传说中的WCF
    python的包管理
    python入门常用方法(转json,模拟浏览器请求头,写入文件)
    python读写数据篇
    python跳坑手记
    python爬虫入门篇
  • 原文地址:https://www.cnblogs.com/CentForever/p/4640729.html
Copyright © 2020-2023  润新知