The purpose of this code is to open a file, read a passage and delete any word that is "secret", it is then to save the new passage to a new file.

Problem:
[Warning] passing arg 1 of `strcmp' makes pointer from integer without a cast
I think I know what the warning is telling me but I don't know enough to fix it.

Any idea what is wrong and how I can fix it? I think my code should work except for what ever that warning is.

I hope I entered the code correctly here, I am new to this type of forum posting.

#include <stdio.h>

int main (int argc, char *argv[]) //Passing arguemnts to main function.
{
        FILE *in, *out; //Declaring both pointers as files
        int c;
        

        if( argc != 3 ) {       //Checking that there are a total of three arguments passed
                fprintf (stderr, "Need two file names\n");      //If there are not three arguments, it will cause a standard error
                return 1;
        }

        if ( (in = fopen(argv[1], "r")) == NULL ) {           //First pointer that will open the file in read only mode file will onle be read
                fprintf (stderr, "Cant read  %s.\n", argv[1]);  //If the file is not located it will return a null file returning an error
                return 2;
        }

        if ( (out = fopen (argv[2], "w")) == NULL ) {           //Second pointer that will open the file in write mode that will be written into
                fprintf (stderr, "Cant write %s.\n", argv[2]); //File will automatially be created by the the terminal
                return 3;
        }

        while( (c = getc(in)) != EOF) {                //While loop will get all the characters stored in the read file and save then onto c
                if (strcmp(c, "secret") == 0)   {                       //If statement will check for the letter s and replace it will a space.
                        c = "_____";
                        }
                else
                putc(c,out);            //After the caharacters have been stored in c, all the caharacters will then be transfered into the the out file
}
        printf ("File has been copied. \n");

        fclose (in);
        fclose (out);

        return 0;
}

your trying to compare an integer(c) and a string(secret)

So how can I fix this problem.

I tried char c; and char c [10]; but the same msg still appears

#include<string.h>

include this library

Ty that fixed that problem, but there is still another one.

[Warning] passing arg 1 of `strcmp' makes pointer from integer without a cast
c was declared as int which is why I am getting the warning that strcmp is pointer...I think that is what it is saying, but I dont think I want c as a pointer so how can this be fixed?

have you declared c as a string(array of char)?
also on which line is that error?

Edited 4 Years Ago by zeroliken: n/a

have you declared c as a string(array of char)?
also on which line is that error?

Yes I have tried array of char (char c[10]) if that is correct.
If not then I dont know what you mean.

Also the error is on line 25-26 (the line right after the while loop line.

Edited 4 Years Ago by DiabloInC: n/a

This article has been dead for over six months. Start a new discussion instead.