0

I define a function

int find(char *t, int len){
}

then i call it with

value = "hello world";
rt = find(value, strlen(value));

it does not work, and show "error: too many arguments to function ‘find’"

the_drow
  • 17,855
  • 25
  • 122
  • 190
why
  • 22,477
  • 27
  • 94
  • 137
  • 4
    The code posted will give an error about a missing semicolon. Try posting the EXACT code you're passing to the compiler -- there's probably some missing punctuation that is confusing the compiler and causing it to give a misleading error message. – Chris Dodd Jan 05 '11 at 05:51
  • 4
    Is this all done in one file or separate files? Has the definition or a prototype for `find)` been 'seen' before the call site (ie., do you do something like include a header that has `int find(char*,int);` in it)? – Michael Burr Jan 05 '11 at 05:51
  • thanks! Burr! I miss the header – why Jan 05 '11 at 06:02

4 Answers4

3
int find(char *t, int len){
}

might give a warning that function should return a value.

and if you add:

char* value = "hello world";
int rt = find(value, strlen(value));

It should work fine if the code is in a single file (as already pointed by Michael in comments) else you will have to specify the prototype of find function before calling it from a separate file.

Vikram.exe
  • 4,485
  • 3
  • 28
  • 39
0
  1. There is a syntax error in your call, no ; after value = "hello world"

  2. Did you #include <string.h>?

milkypostman
  • 2,865
  • 24
  • 22
0

This error might occur when there is difference in arguments between function declaration and function definition.

iamnagaky
  • 803
  • 6
  • 7
0

There are two errors that I found in the above code .

You have to mention the 'return' keyword at the end of the function definition .

You have to declare the character pointer (char * value) while initialize the 'value' .

Usman
  • 2,322
  • 14
  • 26