Iam having problem with the following code:

All this code does is extract words separated by spaces from string

when i compile it i get error27 C:\Dev-Cpp\Untitled1.cpp invalid operands of types `char*' and `char*' to binary `operator*'


plzzzz help

// Tokenizing program:pointer version

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    char str[80];
    char token[80];
    char *p;
    char *q;
    
    cout<<"Enter a sentence: ";
    gets(str);
    p=str;
    
    // Read a token at a time from the string
    while(*p){
              q=token;
              /* Read character until either a space or the null terminator is encountered
              */
              while(*p!=' ' && *p){
                          *q=*p;
                          q++;p++;
                          }
                          if(*p)p++
                          *q = '\0';
                          cout<<token<<"\n";
                          }
                          system("pause");
                          return 0;
                          }

1. You forget semicolon after if statement:

if (*p)
   p++; // ***
*q = '\0';

2. Use code tag for your snippets on this forum:
[code=cplusplus] your code

[/code]
3. Make a proper source code indentation. You write C++ programs, not adult's graffiti...

> Make a proper source code indentation. You write C++ programs, not adult's graffiti...
The indentations in code don't show up when you don't use code tags. I added code tags for him and now his code appears properly indented. (Hence the purpose of code tags)

Thank you, Csgal. I was not on the spot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.