|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
hi all, im doing this problem with string manipulation (C programming on MS Visual Studio 2005 Pro Ed.) and im crapping out on calling this function that i have under routines.cpp when trying to call it from main.cpp
the function prototype (which i have under routines.h) is: int tokenize(char *token[ ], int max_tokens, char *str); and i have the actual function in routines.cpp as this: Code:
#include "routines.h"
#include <stdio.h>
#include <string.h>
int tokenize(char token[ ], int max_tokens, char *str)
{
printf("%s\n%s\n\n%s\n",
"The string to be tokenized is:", token,
"The tokens are:" );
str = strtok (token, " ");
while (str != NULL) {
printf("%s\n", str);
str = strtok(NULL, " ");
}
return 0;
}
and so, if i wanted to call this function from main.cpp how would i do that? i have: tokenize(*token, max_tokens, *str); but i know its wrong because it wont compile. Please help on how to call this function from main.cpp, i have horrible skills with calling functions. THANK YOU IN ADVANCE Last edited by WingedPanther; 04-03-2008 at 03:42 PM. Reason: Add code tags |
| Sponsored Links |
|
|
|
|||||
|
First observation: your definition and declaration disagree. One has type char * [], the other char [] for the first parameter.
What error messages are you getting?
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
|
|||
|
well i went back to routines.cpp and fixed the agreement but i still get 3 error messages when i compile (that is when i compile and calling the tokenizing function as: tokenize( *token, max_token, *str);
these are the errors: error C2065: 'max_tokens' : undeclared identifier error C2065: 'str' : undeclared identifier error C2664: 'strtok' : cannot convert parameter 1 from 'char *[]' to 'char *' and im calling the function tokenize( *token, max_token, *str); under main.cpp |
|
|||||
|
The first two errors mean you have to declare the variables in main() before you can use them.
The third error means your function declaration/definition should be: int tokenize(char *token, int max_tokens, char *str);
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
|
|||||
|
You're very welcome
![]()
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| Xav | ........ | 161.68 |
| neerlin | ........ | 100 |
| satrian | ........ | 100 |
| delia | ........ | 100 |
| chili5 | ........ | 70.08 |
| morefood2001 | ........ | 42.41 |
| MeTh0Dz|Reb0rn | ........ | 28.44 |
| RyanTuosto | ........ | 20 |
| gamiR | ........ | 19.64 |
| John | ........ | 14.46 |
Goal: 100,000 Posts
Complete: 68%