strtok

hey, trying to remove puncuation from a c-string. I'm sure there are better ways but assignment wants it like this(including void main)
everything works down to the while loop(commented out), im able to copy the first word into newstr and then i want to add the rest of the sentence(strcat?)
know im missing something simple


#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif



#include<iostream>
#include<cstring>
using namespace std;
void tokenizer(char[]);
void main()
{
bool b;
char str[80];
cout << "please enter a c-string" << endl;
cin.getline(str, sizeof(str), '\n');
cout << str << endl;
tokenizer(str);
cout << str << endl;


}
void tokenizer(char c[])
{

char newstr[80], *tokenptr;
tokenptr = strtok(c, " ,.?;:!");
strcpy(newstr, tokenptr);




/*while (tokenptr != '\0')
{
tokenptr = strtok('\0', " ,.?;:!");
strcat(newstr, tokenptr);

strcpy(c, newstr);*/

}
If all you want to do is remove the "punctuation" there is really no need for strtok(). Instead just iterate through the string and "remove" the offending characters.

By the way in a C++ program main() must be defined to return an int, a decent compiler will issue at worst a warning about not using an int return type, and at best issue an error message.




Topic archived. No new replies allowed.