2
votes

I am getting warning:

miniunz.c:342:25: Passing 'const char *' to parameter of type 'char *' discards qualifiers

in miniunz.c file of the Zip Archive library. Specifically:

const char* write_filename;
fopen(write_filename,"wb"); //// This work fine...........
makedir(write_filename);    //// This line shows warning....

How should this warning be removed so that both work fine?

2
Please try this makedir((char*)write_filename);. hope this will help you.A B
Looks like a bug in the definition of makedir: there is no reason I can see why it shouldn't be able to accept a const char* argument, so you should change it so that it doesBrian Bi

2 Answers

4
votes

As in the miniunz.c file from Zip Code.

The function definition is as follows:

int makedir (newdir)
    char *newdir; 

So by considering that, There are two ways to do this.

  char* write_filename;

              fopen((char*)write_filename,"wb");
                 makedir(write_filename);

OR

  const char* write_filename;

              fopen(write_filename,"wb");
                 makedir((char*)write_filename);

Or Check your makedir() function.

Hope this will help you.

3
votes

An improvement upon the original answer:

You have a function which takes an NSString * as a parameter.

First you need to convert it to a const char pointer with const char *str = [string UTF8String];

Next, you need to cast the const char as a char, calling

makedir((char*)write_filename);

In the line above, you're taking the const char value of write_filename and casting it as a char *and passing it into the makedir function which takes a char * as its argument:

makedir(char * argName)

Hope that's a bit clearer.