Compare integer and pointer

0

Well, I have a question, I'm trying to copy a line to a file but I get an error that says I can not compare an integer with a pointer, can anyone help me? The error is in line ch = getc(file1); and while(ch != EOF)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#define GetCurrentDir getcwd  //get the path of file
#define BUFFER_LEN 1024


int main(){

    char cCurrentPath[FILENAME_MAX];  //get   
    char line[BUFFER_LEN];  //get command line   
    char* argv[100];        //user command   
    char* path= "/bin/";    //set path at bin   
    char *ch;
    char progpath[20];      //full file path
    int argc;               //arg count  
    FILE *file1, *file2;    //Files for history 
    int delete_line, count=0;   //line to delete and counter



while(1){


    file1 = fopen("fileOne","w");
    if(GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
    {
        printf("%s",cCurrentPath);   
    }
    printf("/SimpleShell>> ");                    //print shell prompt

    if(!fgets(line, BUFFER_LEN, stdin))
    {                       //get command and put it in line 
        break;                                //if user hits CTRL+D break
    }
    else if(line, BUFFER_LEN, SIGQUIT){
            fopen("fileOne.c","r");
        ch = getc(file1);
        while(ch != EOF){   
            printf("%s",ch);
        } 
    } 

    if(count<20)
    {
        fputs(argv[100] ,file1);  
    }
    else{
        fclose(file1);
        file1 = fopen("fileOne.c","r"); 
        rewind(file1);        
        file2 = fopen("repicla.c","w"); 
        ch = getc(file1);   
        while(ch != EOF){       
            ch = getc(file1);       
            if(ch != "\n"){         
                count++;            
                if(count != 20){                
                putc(ch, file2);            
                }
            }   
        }   
        fclose(file1);  
        fclose(file2);  
        remove("fileOne.c");    
        rename("replica.c","fileOne.c");    
        fputs(argv[100] ,file1);   
    }
    
asked by anonymous 14.06.2017 / 21:00

1 answer

0

getc() returns a int , not char * . In this int is the ASCII value of the next character in the file. And, really, when you say while (ch != EOF) , you're comparing the value of that character with the value EOF that marks the end of the file, ie there are no more characters to retrieve.

Then you should declare ch as int , not char * . So your program should work properly.

    
14.06.2017 / 23:50