Q:

zip method to iterate over two lists simultaneously in C?

I have two lists with 14 elements each, I created using the following code: 
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "gdal/gdal.h"
#include "gdal/cpl_conv.h"
#include <stdio.h>
#include <time.h>
#include <errno.h>
#include <sys/stat.h>

// Node Structure of Linked-List
typedef struct nlist{
    char *data;
    struct nlist *next;
}Node;

//Declaring global variables
Node *B02_list;
Node *SCL_list;

// Function to replace a string with another 
// string 
char* str_replace(char* string, const char* substr, const char* replacement) {
    char* tok = NULL;
    char* newstr = NULL;
    char* oldstr = NULL;
    int   oldstr_len = 0;
    int   substr_len = 0;
    int   replacement_len = 0;

    newstr = strdup(string);
    substr_len = strlen(substr);
    replacement_len = strlen(replacement);

    if (substr == NULL || replacement == NULL) {
        return newstr;
    }

    while ((tok = strstr(newstr, substr))) {
        oldstr = newstr;
        oldstr_len = strlen(oldstr);
        newstr = (char*)malloc(sizeof(char) * (oldstr_len - substr_len + replacement_len + 1));

        if (newstr == NULL) {
            free(oldstr);
            return NULL;
        }

        memcpy(newstr, oldstr, tok - oldstr);
        memcpy(newstr + (tok - oldstr), replacement, replacement_len);
        memcpy(newstr + (tok - oldstr) + replacement_len, tok + substr_len, oldstr_len - substr_len - (tok - oldstr));
        memset(newstr + oldstr_len - substr_len + replacement_len, 0, 1);

        free(oldstr);
    }

    free(string);

    return newstr;
}

// Function to insert an element to the Linked-List
Node* insert(Node *Head, char *value)
{
    Node *new_string;
    new_string = (Node *)malloc(sizeof(Node));
    new_string->data = malloc(strlen(value)+1);
    strcpy(new_string->data,value);
    Node *check;
    check = (Node *)malloc(sizeof(Node));

    if(Head == NULL){
        Head = new_string;
        Head->next = NULL;
    }
    else{
        check = Head;
        while(check->next != NULL)
            check = check->next;

        check->next = new_string;
        new_string->next = NULL;
    }
    return Head;
}

//Function to check if a string finishes with a suffix
int string_ends_with(const char * str, const char * suffix)
{
    int str_len = strlen(str);
    int suffix_len = strlen(suffix);

    return 
        (str_len >= suffix_len) &&
        (0 == strcmp(str + (str_len-suffix_len), suffix));
}

//Function to show the elements of the Linked-List
void show(Node *Head)
{
    if (Head == NULL){
        return;
    }

    while(Head != NULL) {
        printf("%s\n", Head->data);
        Head=Head->next;
    }
    printf("\n");
}

//Function to find the files in a directory based on a wildcard
Node * recurList(char *basePath, char *suffix)
{
    char path[1000];
    struct dirent *dp;

    DIR *dir = opendir(basePath);
    while ((dp = readdir(dir)) != NULL)
    {
        if (strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0)
        {
            strcpy(path, basePath);
            strcat(path, "/");
           strcat(path, dp->d_name);

        struct stat s;
            if (stat(path, &s) == 0)
            {
                if( s.st_mode & S_IFDIR )
                {
                recurList(path, suffix);
                }
                else if(s.st_mode &S_IFREG)
                {
                if (string_ends_with(path, suffix))
                    B02_list = insert(B02_list, path);
                }
            } 
        }
    }
    return B02_list;
    closedir(dir);
}

//Function to find the SCL files in a directory 
Node * recurListSCL(char *basePath, char *suffix)
{
    char path[1000];
    struct dirent *dp;

    DIR *dir = opendir(basePath);
    while ((dp = readdir(dir)) != NULL)
    {
        if (strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0)
        {
            strcpy(path, basePath);
            strcat(path, "/");
           strcat(path, dp->d_name);

        struct stat s;
            if (stat(path, &s) == 0)
            {
                if( s.st_mode & S_IFDIR )
                {
                recurListSCL(path, suffix);
                }
                else if(s.st_mode &S_IFREG)
                {
                if (string_ends_with(path, suffix))
                    SCL_list = insert(SCL_list, path);
                }
            } 
        }
    }
    return SCL_list;
    closedir(dir);
}

int getCount(Node* head)
{
    int count = 0;
    Node * current = head;
    while (current != NULL)
    {
        count ++;
        current = current ->next;
    }
    return count;
}

int main()
{
    char path[100];
    char suffix[100];

    printf("Enter path to list files: ");
    scanf("%s", path);
    printf("Enter the wildcard: ");
    scanf("%s", suffix);

    Node *B02;
    Node *SCL;
    B02 = recurList(path, suffix);
    printf("Printing B02_head!\n");
    show(B02);
    char *suffix_scl = "SCL_10m.tif";
    SCL = recurListSCL(path, suffix_scl);
    printf("Printing files in SCL head:\n");
    show(SCL);
    int B02_length = 0;
    int SCL_length = 0;
    B02_length = getCount(B02);
    SCL_length = getCount(SCL);
    printf("BO2 of length: %d\n", B02_length);
    printf("SCL of length: %d\n", SCL_length);

    printf("TESTING FOR LOOP\n");
    Node *index;
    Node *index_scl;
    int ctr = 0;
    for ((index = B02) && (index_scl = SCL);
    (index !=NULL) & (index_scl !=NULL); 
    index=index->next, index_scl->next)
    {
        printf("%d\n", ctr);
        ctr++;
        printf("B02 element is:\n%s\n", index->data);
        printf("SCL element is:\n%s\n", index_scl->data);
        printf("-------------------------------\n");
        printf("\n");
    }
    return 0;
}

I want to iterate in the main() function over the two lists I created. However the code gives me the following output, after compilation. 
Enter path to list files: data
Enter the wildcard: B02_10m.tif
Printing B02_head!
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_B02_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180816T155521_N0206_R011_T17PLK_20180816T213001.SAFE/GRANULE/L2A_T17PLK_A016453_20180816T155524/IMG_DATA/R10m/T17PLK_20180816T155521_B02_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180925T155521_N0206_R011_T17PLK_20180925T204924.SAFE/GRANULE/L2A_T17PLK_A017025_20180925T155550/IMG_DATA/R10m/T17PLK_20180925T155521_B02_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180727T155531_N0206_R011_T17PLK_20180727T204908.SAFE/GRANULE/L2A_T17PLK_A016167_20180727T155526/IMG_DATA/R10m/T17PLK_20180727T155531_B02_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180217T155521_N0206_R011_T17PLK_20180217T221531.SAFE/GRANULE/L2A_T17PLK_A013879_20180217T160029/IMG_DATA/R10m/T17PLK_20180217T155521_B02_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180617T155531_N0206_R011_T17PLK_20180617T204705.SAFE/GRANULE/L2A_T17PLK_A015595_20180617T155525/IMG_DATA/R10m/T17PLK_20180617T155531_B02_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180806T155531_N0206_R011_T17PLK_20180806T204419.SAFE/GRANULE/L2A_T17PLK_A016310_20180806T155756/IMG_DATA/R10m/T17PLK_20180806T155531_B02_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180309T155521_N0206_R011_T17PLK_20180309T204813.SAFE/GRANULE/L2A_T17PLK_A014165_20180309T155521/IMG_DATA/R10m/T17PLK_20180309T155521_B02_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20181224T155521_N0207_R011_T17PLK_20181224T191439.SAFE/GRANULE/L2A_T17PLK_A018312_20181224T155529/IMG_DATA/R10m/T17PLK_20181224T155521_B02_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180508T155531_N0206_R011_T17PLK_20180508T223957.SAFE/GRANULE/L2A_T17PLK_A015023_20180508T155528/IMG_DATA/R10m/T17PLK_20180508T155531_B02_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20181124T155521_N0207_R011_T17PLK_20181124T191524.SAFE/GRANULE/L2A_T17PLK_A017883_20181124T155518/IMG_DATA/R10m/T17PLK_20181124T155521_B02_10m.tif
data/selected_files_l2a/S2B_MSIL2A_20180113T155519_N0206_R011_T17PLK_20180113T190318.SAFE/GRANULE/L2A_T17PLK_A004470_20180113T160002/IMG_DATA/R10m/T17PLK_20180113T155519_B02_10m.tif
data/selected_files_l2a/S2B_MSIL2A_20180103T155519_N0206_R011_T17PLK_20180103T221514.SAFE/GRANULE/L2A_T17PLK_A004327_20180103T160032/IMG_DATA/R10m/T17PLK_20180103T155519_B02_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20181025T155521_N0206_R011_T17PLK_20181025T192616.SAFE/GRANULE/L2A_T17PLK_A017454_20181025T155522/IMG_DATA/R10m/T17PLK_20181025T155521_B02_10m.tif

Printing files in SCL head:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180816T155521_N0206_R011_T17PLK_20180816T213001.SAFE/GRANULE/L2A_T17PLK_A016453_20180816T155524/IMG_DATA/R10m/T17PLK_20180816T155521_SCL_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180925T155521_N0206_R011_T17PLK_20180925T204924.SAFE/GRANULE/L2A_T17PLK_A017025_20180925T155550/IMG_DATA/R10m/T17PLK_20180925T155521_SCL_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180727T155531_N0206_R011_T17PLK_20180727T204908.SAFE/GRANULE/L2A_T17PLK_A016167_20180727T155526/IMG_DATA/R10m/T17PLK_20180727T155531_SCL_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180217T155521_N0206_R011_T17PLK_20180217T221531.SAFE/GRANULE/L2A_T17PLK_A013879_20180217T160029/IMG_DATA/R10m/T17PLK_20180217T155521_SCL_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180617T155531_N0206_R011_T17PLK_20180617T204705.SAFE/GRANULE/L2A_T17PLK_A015595_20180617T155525/IMG_DATA/R10m/T17PLK_20180617T155531_SCL_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180806T155531_N0206_R011_T17PLK_20180806T204419.SAFE/GRANULE/L2A_T17PLK_A016310_20180806T155756/IMG_DATA/R10m/T17PLK_20180806T155531_SCL_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180309T155521_N0206_R011_T17PLK_20180309T204813.SAFE/GRANULE/L2A_T17PLK_A014165_20180309T155521/IMG_DATA/R10m/T17PLK_20180309T155521_SCL_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20181224T155521_N0207_R011_T17PLK_20181224T191439.SAFE/GRANULE/L2A_T17PLK_A018312_20181224T155529/IMG_DATA/R10m/T17PLK_20181224T155521_SCL_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20180508T155531_N0206_R011_T17PLK_20180508T223957.SAFE/GRANULE/L2A_T17PLK_A015023_20180508T155528/IMG_DATA/R10m/T17PLK_20180508T155531_SCL_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20181124T155521_N0207_R011_T17PLK_20181124T191524.SAFE/GRANULE/L2A_T17PLK_A017883_20181124T155518/IMG_DATA/R10m/T17PLK_20181124T155521_SCL_10m.tif
data/selected_files_l2a/S2B_MSIL2A_20180113T155519_N0206_R011_T17PLK_20180113T190318.SAFE/GRANULE/L2A_T17PLK_A004470_20180113T160002/IMG_DATA/R10m/T17PLK_20180113T155519_SCL_10m.tif
data/selected_files_l2a/S2B_MSIL2A_20180103T155519_N0206_R011_T17PLK_20180103T221514.SAFE/GRANULE/L2A_T17PLK_A004327_20180103T160032/IMG_DATA/R10m/T17PLK_20180103T155519_SCL_10m.tif
data/selected_files_l2a/S2A_MSIL2A_20181025T155521_N0206_R011_T17PLK_20181025T192616.SAFE/GRANULE/L2A_T17PLK_A017454_20181025T155522/IMG_DATA/R10m/T17PLK_20181025T155521_SCL_10m.tif

BO2 of length: 14
SCL of length: 14
TESTING FOR LOOP
0
B02 element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

1
B02 element is:
data/selected_files_l2a/S2A_MSIL2A_20180816T155521_N0206_R011_T17PLK_20180816T213001.SAFE/GRANULE/L2A_T17PLK_A016453_20180816T155524/IMG_DATA/R10m/T17PLK_20180816T155521_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

2
B02 element is:
data/selected_files_l2a/S2A_MSIL2A_20180925T155521_N0206_R011_T17PLK_20180925T204924.SAFE/GRANULE/L2A_T17PLK_A017025_20180925T155550/IMG_DATA/R10m/T17PLK_20180925T155521_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

3
B02 element is:
data/selected_files_l2a/S2A_MSIL2A_20180727T155531_N0206_R011_T17PLK_20180727T204908.SAFE/GRANULE/L2A_T17PLK_A016167_20180727T155526/IMG_DATA/R10m/T17PLK_20180727T155531_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

4
B02 element is:
data/selected_files_l2a/S2A_MSIL2A_20180217T155521_N0206_R011_T17PLK_20180217T221531.SAFE/GRANULE/L2A_T17PLK_A013879_20180217T160029/IMG_DATA/R10m/T17PLK_20180217T155521_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

5
B02 element is:
data/selected_files_l2a/S2A_MSIL2A_20180617T155531_N0206_R011_T17PLK_20180617T204705.SAFE/GRANULE/L2A_T17PLK_A015595_20180617T155525/IMG_DATA/R10m/T17PLK_20180617T155531_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

6
B02 element is:
data/selected_files_l2a/S2A_MSIL2A_20180806T155531_N0206_R011_T17PLK_20180806T204419.SAFE/GRANULE/L2A_T17PLK_A016310_20180806T155756/IMG_DATA/R10m/T17PLK_20180806T155531_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

7
B02 element is:
data/selected_files_l2a/S2A_MSIL2A_20180309T155521_N0206_R011_T17PLK_20180309T204813.SAFE/GRANULE/L2A_T17PLK_A014165_20180309T155521/IMG_DATA/R10m/T17PLK_20180309T155521_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

8
B02 element is:
data/selected_files_l2a/S2A_MSIL2A_20181224T155521_N0207_R011_T17PLK_20181224T191439.SAFE/GRANULE/L2A_T17PLK_A018312_20181224T155529/IMG_DATA/R10m/T17PLK_20181224T155521_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

9
B02 element is:
data/selected_files_l2a/S2A_MSIL2A_20180508T155531_N0206_R011_T17PLK_20180508T223957.SAFE/GRANULE/L2A_T17PLK_A015023_20180508T155528/IMG_DATA/R10m/T17PLK_20180508T155531_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

10
B02 element is:
data/selected_files_l2a/S2A_MSIL2A_20181124T155521_N0207_R011_T17PLK_20181124T191524.SAFE/GRANULE/L2A_T17PLK_A017883_20181124T155518/IMG_DATA/R10m/T17PLK_20181124T155521_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

11
B02 element is:
data/selected_files_l2a/S2B_MSIL2A_20180113T155519_N0206_R011_T17PLK_20180113T190318.SAFE/GRANULE/L2A_T17PLK_A004470_20180113T160002/IMG_DATA/R10m/T17PLK_20180113T155519_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

12
B02 element is:
data/selected_files_l2a/S2B_MSIL2A_20180103T155519_N0206_R011_T17PLK_20180103T221514.SAFE/GRANULE/L2A_T17PLK_A004327_20180103T160032/IMG_DATA/R10m/T17PLK_20180103T155519_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

13
B02 element is:
data/selected_files_l2a/S2A_MSIL2A_20181025T155521_N0206_R011_T17PLK_20181025T192616.SAFE/GRANULE/L2A_T17PLK_A017454_20181025T155522/IMG_DATA/R10m/T17PLK_20181025T155521_B02_10m.tif
SCL element is:
data/selected_files_l2a/S2A_MSIL2A_20180408T155531_N0206_R011_T17PLK_20180408T204658.SAFE/GRANULE/L2A_T17PLK_A014594_20180408T155557/IMG_DATA/R10m/T17PLK_20180408T155531_SCL_10m.tif
-------------------------------

I am just wondering if there is method to effectively iterate over two lists in C simultaneously, compared to the built-in methods in Python like zip?
How to iterate through two lists in parallel?
My best try was the one in the code, but although I declared the scl_index in the next iteration it has to be the next value in the linked-list, it returns in every iteration the next value of B02 (which is the first desirable output), but sticks with the very first element of the second linked-list all the way until all elements of the first list are depleted. 
Have anyone an idea about it. !?

A:

The problem is in the for loop.
You should modify it to 
for (index = B02,index_scl = SCL; 
    (index !=NULL) && (index_scl !=NULL); 
     index=index->next,index_scl = index_scl->next)
{
    ...
}

