C Language Text Input/Output Questions

Asked 2 years ago, Updated 2 years ago, 73 views

#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++;
}

(I don't know here.)
if( number_positive > number_negative ) {
printf("This review is positive");
} } else {
printf("This review is negative");
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
}

It's a coding that compares positive and negative words in a C language text file, but it doesn't work well even if you keep putting code in the middle. I need your help

c coding

2022-09-20 14:22

1 Answers

It's not the middle, but the beginning is wrong.

In short, The number of good words > the number of bad words → Good review is correct, right?
Then if you can find the word in fp1 for all the lines in fp3, you should do number_positive++ each time.
Not count++.

Think about it! I think you can do it yourself.


2022-09-20 14:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.