편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2022.12.01

    c언어 텍스트 파일


    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h> 
    #include <string.h>
    void main() {
        FILE* fp1;
        FILE* fp2;
        FILE* fp3;
        char p_words[2006][256];
        char n_words[4783][256];
        int number_positive = 0;
        int number_negative = 0;
        fp1 = fopen("positive-words.txt", "r");
        if (fp1 == NULL) {
            fprintf(stderr, "we cannot open the file\n");
            exit(1);
        }
        fp2 = fopen("negative-words.txt", "r");
        if (fp2 == NULL) {
            fprintf(stderr, "we cannot open the file\n");
            exit(1);
        }
        fp3 = fopen("cv000_29416.txt", "r");
        if (fp3 == NULL) {
            fprintf(stderr, "we cannot open the file\n");
            exit(1);
        }
            int count = 0;
        while (fgets(p_words[count], 256, fp1)) {
            count++;
        }
        count = 0;
        while (fgets(n_words[count], 256, fp2)) {
            count++;
        }
        // print list of positive words 
        for (int i = 0; i < 2006; i++) {
            printf("%s", p_words[i]);
        }
        //(이 부분)
        if (number_positive > number_negative) {
            printf("This review is positive");
        }
        else {
            printf("This review is negative");
        }
        fclose(fp1);
        fclose(fp2);
        fclose(fp3);
    }
    

    하나의 파일을 읽어서 긍정 단어가 많은지 부정 단어가 많은지 판단하는 프로그램인데 이 부분이라고 써있는 부분을 못하겠어요.

  • 프로필 고규헌님의 편집
    날짜2022.11.30

    c언어 텍스트 파일


    define _CRT_SECURE_NO_WARNINGS

    include

    include

    void main() { FILE* fp1; FILE* fp2; FILE* fp3; char p_words[2006][256]; char n_words[4783][256]; int number_positive = 0; int number_negative = 0; fp1 = fopen("positive-words.txt", "r"); if (fp1 == NULL) { fprintf(stderr, "we cannot open the file\n"); exit(1); } fp2 = fopen("negative-words.txt", "r"); if (fp2 == NULL) { fprintf(stderr, "we cannot open the file\n"); exit(1); } fp3 = fopen("cv000_29416.txt", "r"); if (fp3 == NULL) { fprintf(stderr, "we cannot open the file\n"); exit(1); } int count = 0; while (fgets(p_words[count], 256, fp1)) { count++; } count = 0; while (fgets(n_words[count], 256, fp2)) { count++; } // print list of positive words for (int i = 0; i < 2006; i++) { printf("%s", p_words[i]); } //(이 부분) if (number_positive > number_negative) { printf("This review is positive"); } else { printf("This review is negative"); } fclose(fp1); fclose(fp2); fclose(fp3); } 하나의 파일을 읽어서 긍정 단어가 많은지 부정 단어가 많은지 판단하는 프로그램인데 이 부분이라고 써있는 부분을 못하겠어요.ㅠㅠ