Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

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.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-03-2008, 02:28 PM
hybridalter hybridalter is offline
Newbie
 
Join Date: Apr 2008
Posts: 7
Rep Power: 0
hybridalter is on a distinguished road
Red face Help! Problem with string manipulation and using tokens??

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-03-2008, 03:44 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,050
Last Blog:
wxWidgets is NOT code ...
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: Help! Problem with string manipulation and using tokens??

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-03-2008, 03:49 PM
hybridalter hybridalter is offline
Newbie
 
Join Date: Apr 2008
Posts: 7
Rep Power: 0
hybridalter is on a distinguished road
Unhappy Re: Help! Problem with string manipulation and using tokens??

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-03-2008, 04:47 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,050
Last Blog:
wxWidgets is NOT code ...
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: Help! Problem with string manipulation and using tokens??

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-03-2008, 05:20 PM
hybridalter hybridalter is offline
Newbie
 
Join Date: Apr 2008
Posts: 7
Rep Power: 0
hybridalter is on a distinguished road
Thumbs up Re: Help! Problem with string manipulation and using tokens??

hey thanks a lot i got it to work, thanks!!!!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 04-04-2008, 08:04 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,050
Last Blog:
wxWidgets is NOT code ...
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: Help! Problem with string manipulation and using tokens??

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 12:00 AM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
LogicKills ........ 20.00000
sam ........ 20.00000
gaylo565 ........ 18.00000
|pH| ........ 15.00000
WingedPanther ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 67%

Ads