samedi 29 juin 2019

How to compare the two different positions in the file in C?

I am implementing the program to zip a file using a run-length encoding compression method. Are there any ways you can compare the characters in the file or compare two file pointers to do that?

I opened the file(zipfilename) that I want to zip and set the file pointer named ftozip to it. Then, I tried to count the number of each character using this file pointer as shown in the code below (if condition).

    FILE *ftozip;
    ftozip = fopen(argv[1],"r");//open the file that we are zipping
    if (ftozip == NULL) {//if there is an error opening
            perror("File cannot be opened ");
    }
    char zipfilename[30];
    strcat(zipfilename, argv[1]);
    strcat(zipfilename,".zip");
    FILE *zipfilep = fopen(zipfilename, "a"); //zipfile openned to write

    int count = 1;
    while(1){ //incrementing the characters and storing in the zip  file
            if(*ftozip == *(ftozip +1)) {
                    count++;
                    char countchar[] = (char)count+(*ftozip);
                    fputs(countchar, zipfilep);
                    ftozip++;
                    continue;
            }
            else {
                    count = 1;
                    countchar = (char)count + (*ftozip);
                    ftozip++;
                    if (feop(ftozip){
                            break;
                    }
                    continue;
            }

}

That resulting in this error "invalid operands to binary == (have ‘FILE’ and ‘FILE’)".

Aucun commentaire:

Enregistrer un commentaire