20160223.CCPP体系详解(0033天)

Posted 尹成

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了20160223.CCPP体系详解(0033天)相关的知识,希望对你有一定的参考价值。

程序片段(01):MyArray.h+MyArray.c+main.c
内容概要:数组库

///MyArray.h
#pragma once

#define DT int//类型通用

typedef struct

    DT * pStart;//起始地址
    int len;//元素个数
    int sortState;//排序状态(0无序+1有序)
Array;

typedef struct

    DT ** ppStart;
    int len;
ResArray;

void initArray(Array * pArray);
void initArrayWithData(Array * pArray, DT data);
void initArrayWithDatas(Array * pArray, DT * pDatas, int pDatasLen);
void showArray(Array * pArray);
void    arrayAddData(Array * pArray, DT data);
void arrayAddDatas(Array * pArray, DT * pDatas, int pDatasLen);
DT * arrayFindFirstData(Array * pArray, DT data);
ResArray arrayFindAllDatas(Array * pArray, DT data);
void arrayInsertData(Array * pArray, DT data, DT insertData);
void arrayInsertDatas(Array * pArray, DT data, DT * pInsertDatas, int pInsertDatasLen);
void arrayDelFirstData(Array * pArray, DT data);
void arrayDelAllData(Array * pArray, DT data);
void arrayUpdateFirstData(Array * pArray, DT oldData, DT newData);
void arrayUpdateAllData(Array * pArray , DT oldData, DT newData);
//扩展功能:
//  1.排序:
//      冒泡(左右)-->选择-->插入-->快速(单线程)-->希尔(多线程)-->堆排序
//  2.查找:
//      二分-->插值
//  3.可变:
//      可变参数
//  4.多线程检索
///MyArray.c
#include "MyArray.h"
#include <stdlib.h>
#include <memory.h>
#include <stdio.h>

void initArray(Array * pArray)

    if (NULL == pArray)
    
        printf("init error! \\n");
        abort();
    
    pArray->pStart = NULL;
    pArray->len = 0;
    pArray->sortState = 0;


void initArrayWithData(Array * pArray, DT data)

    if (NULL == pArray)
    
        printf("init error! \\n");
        abort();
    
    pArray->pStart = (DT *)malloc(sizeof(DT));
    *(pArray->pStart) = data;
    pArray->len = 1;
    pArray->sortState = 0;


void initArrayWithDatas(Array * pArray, DT * pDatas, int pDatasLen)

    if (NULL == pArray)
    
        printf("init error! \\n");
        abort();
    
    pArray->pStart = (DT *)malloc(pDatasLen * sizeof(DT));
    memcpy(pArray->pStart, pDatas, pDatasLen * sizeof(DT));
    pArray->len = pDatasLen;
    pArray->sortState = 0;


void showArray(Array * pArray)

    if (NULL == pArray || NULL == pArray->pStart || 0 == pArray->len)
    
        printf("没有数据咋打印? \\n");
        abort();
    
    printf("数组此时状态: \\n");
    for (int i = 0; i < pArray->len; ++i)
    //优先级问题:从第一个标识符开始进行判断(从左往右不断结合)
        printf("%4d", pArray->pStart[i]);
    


void arrayAddData(Array * pArray, DT data)

    if (NULL == pArray)
    
        printf("数组根本不存在! \\n");
        abort();
    
    if (NULL == pArray->pStart)
    
        initArrayWithData(pArray, data);
    
    else
    
        pArray->pStart = (DT *)realloc(pArray->pStart, (pArray->len + 1) * sizeof(DT));
        pArray->pStart[pArray->len] = data;
        ++pArray->len;
    


void arrayAddDatas(Array * pArray, DT * pDatas, int pDatasLen)

    if (NULL == pArray)
    
        printf("数组根本不存在! \\n");
        abort();
    
    if (NULL == pArray->pStart)
    
        initArrayWithDatas(pArray, pDatas, pDatasLen);
    
    else
    
        pArray->pStart = (DT *)realloc(pArray->pStart, (pArray->len + pDatasLen) * sizeof(DT));
        memcpy(pArray->pStart + pArray->len, pDatas, pDatasLen * sizeof(DT));
        pArray->len += pDatasLen;
    


DT * arrayFindFirstData(Array * pArray, DT data)

    if (NULL == pArray)
    
        printf("数组根本不存在! \\n");
        abort();
    
    if (NULL == pArray->pStart)
    
        printf("数组未初始化数据! \\n");
        abort();
    
    if (0 == pArray->len)
    
        printf("数组没有数据! \\n");
        abort();
    
    for (int i = 0; i < pArray->len; ++i)
    
        if (data == *(pArray->pStart + i))
        
            return pArray->pStart + i;
        
    
    return NULL;


ResArray arrayFindAllDatas(Array * pArray, DT data)

    if (NULL == pArray)
    
        printf("数组根本不存在! \\n");
        abort();
    
    if (NULL == pArray->pStart)
    
        printf("数组未初始化数据! \\n");
        abort();
    
    ResArray resArray;
    resArray.len = 0;
    for (int i = 0; i < pArray->len; ++i)
    
        if (data == pArray->pStart[i])
        
            ++resArray.len;
        
    
    resArray.ppStart = (DT **)malloc(resArray.len * sizeof(DT *));
    int j = 0;
    for (int i = 0; i < pArray->len; ++i)
    
        if (data == pArray->pStart[i])
        
            resArray.ppStart[j++] = pArray->pStart + i;
        
    
    return resArray;


void arrayInsertData(Array * pArray, DT data, DT insertData)

    if (NULL == pArray)
    
        printf("数组根本不存在! \\n");
        abort();
    
    if (NULL == pArray->pStart)
    
        printf("数组没有初始化数据! \\n");
        abort();
    
    if (0 == pArray->len)
    
        printf("数组没有数据! \\n");
        abort();
    
    DT * pFindData = arrayFindFirstData(pArray, data);
    if (NULL == pFindData)
    
        printf("未能找到数据待插入的位置! \\n");
        abort();
    
    int relPos = pFindData - pArray->pStart;
    pArray->pStart = (DT *)realloc(pArray->pStart, (pArray->len + 1) * sizeof(DT));
    for (int i = pArray->len; i >= relPos; --i)
    
        *(pArray->pStart + i + 1) = *(pArray->pStart + i);
    
    *(pArray->pStart + relPos) = insertData;
    ++pArray->len;


void arrayInsertDatas(Array * pArray, DT data, DT * pInsertDatas, int pInsertDatasLen)

    if (NULL == pArray)
    
        printf("数组根本不存在! \\n");
        abort();
    
    if (NULL == pArray->pStart)
    
        printf("数组未初始化数据! \\n");
        abort();
    
    if (0 == pArray->len)
    
        printf("数组没有数据! \\n");
        abort();
    
    DT * pFindData = arrayFindFirstData(pArray, data);
    if (NULL == pFindData)
    
        printf("未能找到数据待插入的位置! \\n");
        abort();
    
    int relPos = pFindData - pArray->pStart;
    pArray->pStart = (DT *)realloc(pArray->pStart, (pArray->len + pInsertDatasLen) * sizeof(DT));
    for (int i = pArray->len; i >= relPos; --i)
    
        *(pArray->pStart + i + pInsertDatasLen) = *(pArray->pStart + i);
    
    memcpy(pArray->pStart + relPos, pInsertDatas, pInsertDatasLen * sizeof(DT));
    pArray->len += pInsertDatasLen;


void arrayDelFirstData(Array * pArray, DT data)

    if (NULL == pArray)
    
        printf("数组不存在! \\n");
        abort();
    
    if (NULL == pArray->pStart)
    
        printf("数组无初始化数据! \\n");
        abort();
    
    if (0 == pArray->len)
    
        printf("数组没有数据! \\n");
        abort();
    
    DT * pFindData = arrayFindFirstData(pArray, data);
    if (NULL == pFindData)
    
        printf("没有找到待删除数据! \\n");
        abort();
    
    int relPos = pFindData - pArray->pStart;
    for (int i = relPos; i < pArray->len - 1; ++i)
    
        *(pArray->pStart + i) = *(pArray->pStart + i + 1);
    
    --pArray->len;
    pArray->pStart = (DT *)realloc(pArray->pStart, pArray->len * sizeof(DT));


void arrayDelAllData(Array * pArray, DT data)

    if (NULL == pArray)
    
        printf("数组不存在! \\n");
        abort();
    
    if (NULL == pArray->pStart)
    
        printf("数组无初始化数据! \\n");
        abort();
    
    if (0 == pArray->len)
    
        printf("数组没有数据! \\n");
        abort();
    
    for (DT * p = arrayFindFirstData(pArray, data); NULL != p; p = arrayFindFirstData(pArray, data))
    
        arrayDelFirstData(pArray, data);
    


void arrayUpdateFirstData(Array * pArray, DT oldData, DT newData)

    if (NULL == pArray)
    
        printf("数组不存在! \\n");
        abort();
    
    if (NULL == pArray->pStart)
    
        printf("数组未初始化数据! \\n");
        abort();
    
    if (0 == pArray->len)
    
        printf("数组没有数据! \\n");
        abort();
    
    DT * pFindData = arrayFindFirstData(pArray, oldData);
    if (NULL == pFindData)
    
        printf("未能找到待替换的数据! \\n");
        abort();
    
    *pFindData = newData;


void arrayUpdateAllData(Array * pArray, DT oldData, DT newData)

    if (NULL == pArray)
    
        printf("数组不存在! \\n");
        abort();
    
    if (NULL == pArray->pStart)
    
        printf("数组未初始化数据! \\n");
        abort();
    
    if (0 == pArray->len)
    
        printf("数组没有数据! \\n");
        abort();
    
    for (DT * p = arrayFindFirstData(pArray, oldData); NULL != p; p = arrayFindFirstData(pArray, oldData))
    
        arrayUpdateFirstData(pArray, oldData, newData);
    
///main.c
#include "MyArray.h"
#include <stdlib.h>

int main(void)

    Array array;
    //initArrayWithData(&array, 1);
    int intArr1[5] =  1, 2, 3, 4, 5 ;
    initArrayWithDatas(&array, intArr1, 5);
    //arrayAddData(&array, 6);
    int intArr2[3] =  6, 7, 8 ;
    arrayAddDatas(&array, intArr2, 3);
    //arrayInsertData(&array, 6, 7);
    int intArr3[3] =  8, 9, 10 ;
    arrayInsertDatas(&array, 6, intArr3, 3);
    //arrayDelFirstData(&array, 6);
    //arrayDelAllData(&array, 8);
    //arrayUpdateFirstData(&array, 8, 11);
    arrayUpdateAllData(&array, 8 ,11);
    showArray(&array);


    system("pause");



//void main()
//
//  struct array  mydata;
//  int  a[10] =  1, 2, 6, 4, 5, 6, 7, 8, 9, 6 ;
//  int b[5] =  11, 12, 13, 14 ;
//  int c[4] =  21, 22, 23, 24 ;
//  initwitharray(&mydata, a, 10);
//  show(&mydata);
//
//  //changeallobject(&mydata, 6, 660);
//  //changefirstobject(&mydata,5, 950);
//  //insertobjects(&mydata, 8, c, 4);
//  //deleteallobject(&mydata, 6);
//  //deletefirstobject(&mydata, 6);
//  //addobjects(&mydata, b, 5);
//  //addobjects(&mydata, c, 4);
//  //insertobject(&mydata, 1,999);//根据位置插入
//  struct  Res res = findall(&mydata, 6);
//  for (int i = 0; i < res.n;i++)
//  
//      printf("\\n%p,%d", res.ppstart[i], *res.ppstart[i]);
//  
//  
//  show(&mydata);
//
//
//
//
//
//
//  system("pause");
//

程序片段(02):MyArray.h+MyArray.c+main.c
内容概要:数组库

///MyArray.h
#pragma once

//#define DT int
#define DT char *

typedef struct

    DT * pStart;
    int len;
    int sortState;
Array;

typedef struct

    DT ** ppStart;
    int len;
ResArray;

typedef int (* EqualFunP)(DT *, DT *);
typedef void(*PrintFunP)(Array * pArray);


void initArray(Array * pArray);
void initArrayWithData(Array * pArray, DT data);
void initArrayWithDatas(Array * pArray, DT * pDatas, int pDataLen);

int isValidA(Array * pArray);
int isValidB(Array * pArray);
int isValidC(Array * pArray);
int isValidD(Array * pArray);
int isValidE(Array * pArray);

void printInt(Array * pArray);
void printString(Array * pArray);

void showArray(Array * pArray, PrintFunP funP);

void arrayAddData(Array * pArray, DT data);
void arrayAddDatas(Array * pArray, DT * pDatas, int pDatasLen);

int intIsEqual(int * pDataA, int * pDataB);
int strIsEqual(char ** pDataA, char ** pDataB);
DT *    arraySelectFirstData(EqualFunP funP, Array * pArray, DT data);
ResArray arraySelectAllDatas(EqualFunP funP, Array * pArray, DT data);

void arrayInsertData(Array * pArray, DT data, DT insertData);
void arrayInsertDatas(Array * pArray, DT data, DT * pInsertDatas, int pInsertDatasLen);

void arrayDeleteFirstData(Array * pArray, DT data);
void arrayDeleteAllDatas(Array * pArray, DT data);

void arrayUpdateFirstData(Array * pArray, DT oldData, DT newData);
void arrayUpdateAllDatas(Array * pArray, DT oldData, DT newData);
//数组库拓展功能:
//  1.排序:
//      冒泡->选择->插入->堆排序->快速(单线程)->希尔(多线程)
//  2.查找:
//      二分->插值->多线程
//  3.可变参数
//      可变参数拓展
///MyArray.c
#include "MyArray.h"
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <string.h>

void initArray(Array * pArray)

    if (NULL == pArray)
    
        printf("数组不存在! \\n");
        abort();
    
    (*pArray).pStart = NULL;
    (*pArray).len = 0;
    (*pArray).sortState = 0;


void initArrayWithData(Array * pArray, DT data)

    if (NULL == pArray)
    
        printf("数组不存在! \\n");
        abort();
    
    (*pArray).pStart = (DT *)malloc(sizeof(DT));
    *((*pArray).pStart) = data;
    (*pArray).len = 1;
    (*pArray).sortState = 0;


void initArrayWithDatas(Array * pArray, DT * pDatas, int pDatasLen)

    if (NULL == pArray)
    
        printf("数组不存在! \\n");
        abort();
    
    (*pArray).pStart = (DT *)malloc(pDatasLen*sizeof(DT));
    memcpy((*pArray).pStart, pDatas, pDatasLen * sizeof(DT));
    (*pArray).len = pDatasLen;
    (*pArray).sortState = 0;


int isValidA(Array * pArray)

    if (NULL == pArray)
    
        printf("数组不存在! \\n");
        return 0;
    
    return 1;


int isValidB(Array * pArray)

    if (NULL == (*pArray).pStart)
    
        printf("数组无初始化数据! \\n");
        return 0;
    
    return 1;


int isValidC(Array * pArray)

    if (0 == (*pArray).len)
    
        printf("数组没有数据! \\n");
        return 0;
    
    return 1;


int isValidD(Array * pArray)

    if (NULL == pArray)
    
        printf("数组不存在! \\n");
        return 0;
    
    if (NULL == (*pArray).pStart)
    
        printf("数组无初始化数据! \\n");
        return 0;
    
    return 1;


int isValidE(Array * pArray)

    if (NULL == pArray)
    
        printf("数组不存在! \\n");
        return 0;
    
    if (NULL == (*pArray).pStart)
    
        printf("数组无初始化数据! \\n");
        return 0;
    
    return 1;


void printString(Array * pArray)

    for (int i = 0; i < (*pArray).len; ++i)
    
        printf("%s \\n", *((*pArray).pStart + i));
    


void printInt(Array * pArray)

    for (int i = 0; i < (*pArray).len; ++i)
    
        printf("%d \\n", *((*pArray).pStart + i));
    


void showArray(Array * pArray, PrintFunP funP)

    if (!isValidE(pArray))
    
        abort();
    
    funP(pArray);


void arrayAddData(Array * pArray, DT data)

    if (!isValidA(pArray))
    
        abort();
    
    if (!isValidB(pArray))
    
        initArrayWithData(pArray, data);
    
    else
    
        (*pArray).pStart = (DT *)realloc((*pArray).pStart, ((*pArray).len + 1) * sizeof(DT));
        *((*pArray).pStart + (*pArray).len) = data;
        ++(*pArray).len;
    


void arrayAddDatas(Array * pArray, DT * pDatas, int pDatasLen)

    if (!isValidA(pArray))
    
        abort();
    
    if (!isValidB(pArray))
    
        initArrayWithDatas(pArray, pDatas, pDatasLen);
    
    else
    
        (*pArray).pStart = (DT *)realloc((*pArray).pStart, ((*pArray).len + pDatasLen) * sizeof(DT));
        memcpy((*pArray).pStart + (*pArray).len, pDatas, pDatasLen * sizeof(DT));
        (*pArray).len += pDatasLen;
    


int intIsEqual(int * pDataA, int * pDataB)

    return *pDataA == *pDataB;


int strIsEqual(char ** pDataA, char ** pDataB)

    return !strcmp(*pDataA, *pDataB);


DT * arraySelectFirstData(EqualFunP funP, Array * pArray, DT data)

    if (!isValidE(pArray))
    
        abort();
    
    for (int i = 0; i < (*pArray).len; ++i)
     
        if (funP(&data, (*pArray).pStart + i))
        
            return (*pArray).pStart + i;
        
    
    return NULL;


ResArray arraySelectAllDatas(EqualFunP funP, Array * pArray, DT data)

    if (!isValidE(pArray))
    
        abort();
    
    ResArray resArr;
    resArr.len = 0;
    for (int i = 0; i < (*pArray).len; ++i)
    
        if (funP(&data, (*pArray).pStart + i))
        
            ++resArr.len;
        
    
    resArr.ppStart = (DT **)malloc(resArr.len * sizeof(DT *));
    int j = 0;
    for (int i = 0; i < (*pArray).len; ++i)
    
        if (funP(&data, (*pArray).pStart + i))
        
            *(resArr.ppStart + j++) = (*pArray).pStart + i;
        
    
    return resArr;


void arrayInsertData(Array * pArray, DT data, DT insertData)

    if (!isValidE(pArray))
    
        abort();
    
    DT * pFindData = arraySelectFirstData(strIsEqual, pArray, data);
    if (NULL == pFindData)
    
        printf("没有找到待插入的位置! \\n");
        abort();
    
    int relPos = pFindData - (*pArray).pStart;
    (*pArray).pStart = (DT *)realloc((*pArray).pStart, ((*pArray).len + 1)*sizeof(DT));
    for (int i = (*pArray).len; i >= relPos; --i)
    
        *((*pArray).pStart + i + 1) = *((*pArray).pStart + i);
    
    *((*pArray).pStart + relPos) = insertData;
    ++(*pArray).len;


void arrayInsertDatas(Array * pArray, DT data, DT * pInsertDatas, int pInsertDatasLen)

    if (!isValidE(pArray))
    
        abort();
    
    DT * pFindData = arraySelectFirstData(strIsEqual, pArray, data);
    if (NULL == pFindData)
    
        printf("没有找到待插入的位置! \\n");
        abort();
    
    int relPos = pFindData - (*pArray).pStart;
    (*pArray).pStart = (DT *)realloc((*pArray).pStart, ((*pArray).len + pInsertDatasLen) * sizeof(DT));
    for (int i = (*pArray).len; i >= relPos; --i)
    
        *((*pArray).pStart + i + pInsertDatasLen) = *((*pArray).pStart + i);
    
    memcpy((*pArray).pStart + relPos, pInsertDatas, pInsertDatasLen * sizeof(DT));
    (*pArray).len += pInsertDatasLen;


void arrayDeleteFirstData(Array * pArray, DT data)

    if (!isValidE(pArray))
    
        abort();
    
    DT * pFindData = arraySelectFirstData(strIsEqual, pArray, data);
    if (NULL == pFindData)
    
        printf("没有找到待删除的位置! \\n");
        abort();
    
    int relPos = pFindData - (*pArray).pStart;
    for (int i = relPos; i < (*pArray).len - 1; ++i)
    
        *((*pArray).pStart + i) = *((*pArray).pStart + i + 1);
    
    --(*pArray).len;
    (*pArray).pStart = (DT *)realloc((*pArray).pStart, (*pArray).len * sizeof(DT));


void arrayDeleteAllDatas(Array * pArray, DT data)

    if (!isValidE(pArray))
    
        abort();
    
    for (DT * p = arraySelectFirstData(strIsEqual, pArray, data); NULL != p; p = arraySelectFirstData(strIsEqual, pArray, data))
    
        arrayDeleteFirstData(pArray, data);
    


void arrayUpdateFirstData(Array * pArray, DT oldData, DT newData)

    if (!isValidE(pArray))
    
        abort();
    
    DT * pFindData = arraySelectFirstData(strIsEqual, pArray, oldData);
    if (NULL == pFindData)
    
        printf("未能找到待更新的位置! \\n");
        abort();
    
    *pFindData = newData;


void arrayUpdateAllDatas(Array * pArray, DT oldData, DT newData)

    if (!isValidE(pArray))
    
        abort();
    
    for (DT * p = arraySelectFirstData(strIsEqual, pArray, oldData); NULL != p; p = arraySelectFirstData(strIsEqual, pArray, oldData))
    
        *p = newData;
    
///main.c
#include "MyArray.h"
#include <stdlib.h>
#include <stdio.h>

int main01(void)

    Array array;
    initArray(&array);

    //initArrayWithData(&array, 1);
    //int intArr[5] =  1, 2, 3, 4, 5 ;
    //initArrayWithDatas(&array, intArr, 5);
    //arrayAddData(&array, 6);
    //int intArr1[3] =  7, 8, 9 ;
    //arrayAddDatas(&array, intArr1, 3);
    //showArray(&array, printInt);

    initArrayWithData(&array, "123");
    char * pArr[5] =  "abc", "def", "ghi", "jkl", "jkl" ;
    initArrayWithDatas(&array, pArr, 5);
    arrayAddData(&array, "opq");
    char * pArr1[3] =  "rst", "uvw", "xyz" ;
    arrayAddDatas(&array, pArr1, 3);
    arrayInsertData(&array, "jkl", "AAA");
    char * pArr2[3] =  "BBB", "CCC", "DDD" ;
    arrayInsertDatas(&array, "jkl", pArr2, 3);
    arrayDeleteFirstData(&array , "AAA");
    arrayDeleteAllDatas(&array, "jkl");
    arrayUpdateFirstData(&array, "BBB", "EEE");
    arrayUpdateAllDatas(&array, "CCC", "FFF");
    showArray(&array, printString);
    //printf("%s \\n", *(arraySelectFirstData(strIsEqual, &array, "uvw")));              
    //ResArray resArr = arraySelectAllDatas(strIsEqual, &array, "jkl");
    //for (int i = 0; i < resArr.len; ++i)
    //
    //  printf("%s \\n", **(resArr.ppStart + i));
    //

    system("pause");

程序片段(03):String.h+Array.h+String.c+Array.c+main.c
内容概要:库中库

///String.h
#pragma once
#include <stdlib.h>

typedef struct

    char * pAStr;
    int memLen;
AString;

typedef struct

    wchar_t * pWStr;
    int memLen;
WString;

void setWStrLocale(char const * pStr);

int strIsValidA(void * pStr);
int strIsValidB(char chr, void * pStr);
int strIsValidC(char chr, void * pStr);

void initStr(char chr, void * pStr);
void initStrWithStr(char chr, void * pStr, void const * pInitStr);
void showStr(char chr, void * pStr);
///Array.h
#pragma once

typedef struct

    int eleSize;
    int len;
    char eleType[12];
    void * pArr;
Array;

void initArray(Array * pArr, char eleType[12], int eleSize);
void initArrayWithDatas(Array * pArr, char eleType[12], int eleSize, void * pInitDatas, int pInitDatasLen);
void showArray(Array * pArr, char eleType[12]);
void arrayAddData(Array * pArr, void * pData);
///String.c
#define _CRT_SECURE_NO_WARNINGS
#include "String.h"
#include <locale.h>
#include <string.h>
#include <stdio.h>

void setWStrLocale(char const * pStr)

    setlocale(LC_ALL, pStr);


int strIsValidA(void * pStr)

    if (NULL == pStr)
    
        printf("字符串不存在! \\n");
        return 0;
    
    return 1;


int strIsValidB(char chr, void * pStr)

    if ('w' == chr)
    
        WString * pAStr = pStr;
        if (NULL == (*pAStr).pWStr)
        
            printf("宽字符串无初始化数据! \\n");
            return 0;
        
    
    else
    
        AString * pWStr = pStr; 
        if (NULL == (*pWStr).pAStr)
        
            printf("宽字符串无初始化数据! \\n");
            return 0;
        
    
    return 1;
         

int strIsValidC(char chr, void * pStr)

    if ('w' == chr)
    
        WString * pWStr = pStr;
        if (0 == wcslen((*pWStr).pWStr))
        
            printf("宽字符串没有数据! \\n");
            return 0;
        
    
    else
    
        AString * pAStr = pStr;
        if (0 == strlen((*pAStr).pAStr))
        
            printf("窄字符串没有数据! \\n");
            return 0;
        
    
    return 1;


void initStr(char chr, void * pStr)

    if (!strIsValidA(pStr))
    
        abort();
    
    if ('w' == chr)
    
        WString * pWStr = pStr;
        (*pWStr).pWStr = NULL;
        (*pWStr).memLen = 0;
    
    else
    
        AString * pAStr = pStr;
        (*pAStr).pAStr = NULL;
        (*pAStr).memLen = 0;
    


void initStrWithStr(char chr, void * pStr, void * pInitStr)

    if (!strIsValidA(pStr))
    
        abort();
    
    if ('w' == chr)
    
        WString * pWStr = pStr;
        wchar_t * pInitWStr = pInitStr;
        int pWStrLen = wcslen(pInitWStr) + 1;
        (*pWStr).pWStr = (wchar_t *)malloc(pWStrLen * 2);
        wcscpy((*pWStr).pWStr, pInitWStr);
        (*pWStr).memLen = pWStrLen;
    
    else
    
        AString * pAStr = pStr;
        char * pInitAStr = pInitStr;
        int pAStrLen = strlen(pInitAStr) + 1;
        (*pAStr).pAStr = (char *)malloc(pAStrLen * sizeof(char));
        strcpy((*pAStr).pAStr, pInitAStr);
        (*pAStr).memLen = pAStrLen;
    


void showStr(char chr, void const * pStr)

    if (!strIsValidA(pStr) || !strIsValidB(chr, pStr) || !strIsValidC(chr ,pStr))
    
        abort();
    
    if ('w' == chr)
    
        WString * pWStr = pStr;
        wprintf(L"%ls \\n", (*pWStr).pWStr);
    
    else
    
        AString * pAStr = pStr;
        printf("%s \\n", (*pAStr).pAStr);
    
///Array.c
#define _CRT_SECURE_NO_WARNINGS
#include "Array.h"
#include "String.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

void initArray(Array * pArr, char eleType[12], int eleSize)

    pArr->pArr = NULL;
    pArr->len = 0;
    pArr->eleSize = eleSize;
    strcpy(pArr->eleType, eleType);


void initArrayWithDatas(Array * pArr, char eleType[12], int eleSize, void * pInitDatas, int pInitDatasLen)

    strcpy((*pArr).eleType, eleType);
    (*pArr).eleSize = eleSize;
    if (!strcmp("WString", eleType))
    
        WString * pWStr = pInitDatas;
        (*pArr).pArr = (WString *)malloc(pInitDatasLen * sizeof(WString));
        memcpy((*pArr).pArr, pWStr, pInitDatasLen * sizeof(WString));
        (*pArr).len = pInitDatasLen;
    
    else if (!strcmp("AString", eleType))
    
        AString * pAStr = pInitDatas;
        (*pArr).pArr = (AString *)malloc(pInitDatasLen * sizeof(AString));
        memcpy((*pArr).pArr, pAStr, pInitDatasLen * sizeof(AString));
        (*pArr).len = pInitDatasLen;
    


void showArray(Array * pArr, char eleType[12])

    if (!strcmp("WString", eleType))
    
        WString * pWStr = (*pArr).pArr;
        for (int i = 0; i < (*pArr).len; ++i)
        
            wprintf(L"%ls \\n", (*(pWStr + i)).pWStr);
        
        printf("\\n");
    
    else if (!strcmp("AString", eleType))
    
        AString * pAStr = (*pArr).pArr;
        for (int i = 0; i < (*pArr).len; ++i)
        
            printf("%s \\n", (*(pAStr + i)).pAStr);
        
        printf("\\n");
    


void arrayAddData(Array * pArr, void * pData)

    if (!strcmp("WString", (*pArr).eleType))
    
        (*pArr).pArr = (WString *)realloc((*pArr).pArr, ((*pArr).len + 1)*sizeof(WString));
        WString * pWStr = pData;
        WString * pTmp = (*pArr).pArr;
        *(pTmp + (*pArr).len) = *pWStr;
        ++(*pArr).len;
    
    else if (!strcmp("AString", (*pArr).eleType))
    
        (*pArr).pArr = (AString *)realloc((*pArr).pArr, ((*pArr).len + 1)* sizeof(AString));
        AString * pAStr = pData;
        AString * pTmp = (*pArr).pArr;
        *(pTmp + (*pArr).len) = *pAStr;
        ++(*pArr).len;
    
///main.c
#include "String.h"
#include "Array.h"

int main01(void)

    setWStrLocale("zh-CN");
    AString  astring;
    WString wstring;
    //initStr('a', &pAStr);
    //initStr('w', &pWStr);
    initStrWithStr('a', &astring, "calc");
    initStrWithStr('w', &wstring ,L"你猜猜");
    showStr('a', &astring);
    showStr('w', &wstring);

    system("pause");

程序片段(04):Row.h+Array.h+init.h+Row.c+Array.c+init.c
内容概要:数据的管理-增删查改线性存储

///Row.h
#pragma once

typedef struct

    long long QQ;
    char * pStr;
    unsigned char len;
Row;

int rowIsValidA(Row * pRow);
int rowIsValidB(Row * pRow);
int rowIsValidC(Row * pRow);
void initRowWithData(Row * pRow, long long QQ, char * pStr);
void initRowWithPass(Row * pRow, char * pPass);
void initRowWithStr(Row * pRow, char * pStr);
void showRow(Row * pRow);
void rowUpdateRow(Row * pOldRow, Row * pNewRow);
void rowUpdateRowDeep(Row * pOldRow, Row * pNewRow);
20160225.CCPP体系详解(0035天)

20160206.CCPP体系详解(0016天)

20160219.CCPP体系详解(0029天)

20160218.CCPP体系详解(0028天)

20160226.CCPP体系详解(0036天)

20160210.CCPP体系详解(0020天)