C语言二维数组的处理实例

时间:2021-09-13 04:16:38

复制代码 代码如下:


char finalPathSet[256][256];
 char middlePathSet[256][256];
 int finalSetSize=0;
 int middleSetSize=0;

int addToPathSet(char path[]){
    strcpy(middlePathSet[middleSetSize],path);
    middleSetSize++;
}
int meetPathSet(){
    char tempPathSet[256][256];
    int tempSetSize=0;
    int i,j;   
    if(finalSetSize==0){
         for(i=0;i<middleSetSize;i++){
            strcpy(finalPathSet[i],middlePathSet[i]);                                       
         }
         finalSetSize=middleSetSize;
    }
    else{
        for(i=0;i<finalSetSize;i++){
            for(j=0;j<middleSetSize;j++){
                if(strcmp(finalPathSet[i],middlePathSet[j])==0){
                     strcpy(tempPathSet[tempSetSize],finalPathSet[i]);
                     tempSetSize++;
                }                                                                               
            }
        }
       for(i=0;i<tempSetSize;i++){
           strcpy(finalPathSet[i],tempPathSet[i]);
       }                         
       finalSetSize=tempSetSize;
    }
}