Проблема с циклом for и несколькими файлами CSV

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
        int a;
        char b[20];
        printf("Input your ID: ");
        scanf("%d", &a);
        getchar();
        printf("Input your name: ");
        gets(b);
        printf("---------");
        printf("Name: %s", b);
        return 0;
}



Note: 
  If you use the scanf first and the fgets second, it will give problem only. It will not read the second character for the gets function. 

  If you press enter, after give the input for scanf, that enter character will be consider as a input f or fgets.
0
задан Robert Petersson 1 March 2019 в 12:28
поделиться

2 ответа

Вы должны сделать что-то подобное, прежде чем открывать какие-либо циклы for:

pdt_list1 = products_list1.readlines()
pdt_list2 = products_list2.readlines()

и выполнять операции с pdt_list1 и pdt_list2.

Это исправит проблему! Удачи!

0
ответ дан Satya 1 March 2019 в 12:28
поделиться

Вы можете попробовать это

with open("./products.csv", mode="r") as products_list1:
    lines1 = products_list1.readlines()
with open("./products2.csv", mode="r") as products_list2:
    lines2 = products_list2.readlines()
with open("./results.csv", mode="a") as results:
    for i in lines1:
        for j in lines2:
            jaccard = get_jaccard_sim(i, j)
            if jaccard >= 0:
                results.writelines(i + "," + j + "\n" + "," + str(jaccard))
0
ответ дан dkb 1 March 2019 в 12:28
поделиться
Другие вопросы по тегам:

Похожие вопросы: