0
Well, I have a question, I’m trying to copy a line to a file but there’s an error that says I can’t compare an integer to a Pointer, can anyone help me?
The error is on the 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);
}
Thanks, I understood the explanation but even so this line of code gives the same error if(ch != ' n')
– Ricardo Pinto
In the code, it’s
if (ch!="\n")
; note double quotes, not simple. This causes"\n"
be the typeconst char []
, so he’s trying to compareint
withchar *
.– Wtrmute