How to fix: undefined is not a function?

Help for C++: How to fix error C2664 on my function?

  • READ ME: This might be a stupid question with an obvious answer, but bear with me because I don't have a programming teacher. I'm teaching myself, and this is the first language I've started to learn and I've started very recently. Okay, so the problem is that I keep getting error C2664: 'strcmp' : cannot convert parameter 2 from 'char [][100]' to 'const char *' The function I am trying to make is one that will search a 2 dimensional character array by checking each row if it matches a 1 dimensional character array, and this is what I have. bool search( char search[] , char list[100][100] , int x ) { for ( int i = 0; i < x; i++ ) { if ( strcmp ( search , list ) == 0 ) return true; else return false; } } This is what I have in the main function: bool searchResult = search( searchEmployee , employeeList , listNumber ); searchEmployee is a character array, employeeList is a character array that has rows and columns, and listNumber is an integer. This is the function prototype: bool search( char[] , char[100][100] , int ); Is there anything I need to change in the coding of the program to get rid of the errors? I really need to fix this error, I have the rest of the code cleaned up. Thanks to anyone in advance :)

  • Answer:

    Change the declaration to this and it should work __ bool search( char search[] , char list[100][100] , int x ) { for ( int i = 0; i < x; i++ ) { if ( strcmp ( search , list[i] ) == 0 ) return true; else return false; } }

AA FTW at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

The error is valid and you must fix your code, it is wrong. Your strcmp should be something like: strcmp(search, &list[i][0]) Personally, I'd never write the code you wrote, but you have to learn to crawl before you can walk.

John H

The main problem, like others have mentioned, is that you need to pass list[i], not just list, to the srtcmp() function. The other problem is that your code will only look at the first item. If it matches it will return true, otherwise it will return false. The correct way is to return true if any of the items match, and then after the loop (if you ever get there) return false. bool search(char search[] , char list[][100] , int x ) {     for ( int i = 0; i < x; i++ )     {         if ( strcmp ( search , list[i] ) == 0 )             return true;     }     return false; // if control gets here, it means it wasn't found }

t

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.