Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <math.h>
- int main(int argc, char * argv[]) {
- if(argc < 4) {
- printf("Ne vnesovte dovolno parametri\n");
- return 0;
- }
- FILE * in1 = fopen(argv[1], "r");
- FILE * in2 = fopen(argv[2], "r");
- FILE * out = fopen(argv[3], "w");
- if(in1 == NULL || in2 == NULL) {
- printf("Ne postoi datotekata\n");
- return 0;
- }
- char d1[2000], d2[2000];
- while(fgets(d1, 150, in1) != NULL && fgets(d2, 150, in2) != NULL) {
- int broj_na_zborovi_d1 = 0, broj_na_zborovi_d2 = 0;
- for(int i = 0; i < strlen(d1); i++) {
- if(d1[i] == ' ') {
- broj_na_zborovi_d1++;
- }
- }
- for(int i = 0; i < strlen(d2); i++) {
- if(d2[i] == ' ') {
- broj_na_zborovi_d2++;
- }
- }
- if(broj_na_zborovi_d1 == broj_na_zborovi_d2) {
- d1[strlen(d1) - 1] = '\0';
- d2[strlen(d2) - 1] = '\0';
- fprintf(out, "%s %s\n", d1, d2);
- }
- else if(broj_na_zborovi_d1 > broj_na_zborovi_d2) {
- d1[strlen(d1) - 1] = '\0';
- fprintf(out, "%s\n", d1);
- }
- else {
- d2[strlen(d2) - 1] = '\0';
- fprintf(out, "%s\n", d2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment