We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,329 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

avoid this warning: passing arg of `fun' discards qualifiers from ptr target type

Hi to all...

I am getting a warning, i am trying to avoid that but its not sorted out..Please suggest me to avoid that warning.

my code is as follows..

const char var[][2][5]={ 
                                 {"1.95","3.70"},
				 {"2.40","4.60"},
				 {"2.70","5.70"},
				 {"6.60","13.40"},
                                        .
                                        .
                                        .
                                        .
                                };
  
  void fun(int col,int row,char *str)
  {
     ...
     ...   //(here i am printing that string...)
  }

  main()
  {
     fun(var[45][1]);
  }

My definition of fun function, array, main function are in the same file.....

main.c(11498): warning: passing arg 3 of `fun' discards qualifiers from pointer target type

So this is the warning i am facing...please suggest me how can i avoid that warning...

2
Contributors
2
Replies
1 Hour
Discussion Span
1 Year Ago
Last Updated
3
Views
Question
Answered
pardhu463
Newbie Poster
5 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

look at the argument list for the function fun() -- it requires three parameters; two integers and a char*. Now look at how you are trying to call that function in main(). It is only passing one parameter instead of three.

This compiles correctly with vc++ 2010 express. Note the last dimension must be 6 instead of 5 because "13.40" requires 6 bytes including the null terminator.

const char var[][2][6]={ 
    {"1.95","3.70"},
    {"2.40","4.60"},
    {"2.70","5.70"},
    {"6.60","13.40"}
};

void fun(int col,int row,const char *str)
{
}
int main()
{
    fun(0,0,var[0][0]);
}
Ancient Dragon
Achieved Level 70
Team Colleague
32,139 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69

Thank you..very much for your quick response....i managed to avoid them....

pardhu463
Newbie Poster
5 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Ancient Dragon

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0715 seconds using 2.68MB