Problem with strcmp

Hey, i have a little problem ..
when the input == nop is comes a error on my screen and it returns with

Process exited with return value 3221225477

can anybody help me ?

there is the src :

//Header
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

//Variablen
char Code [1024];
char delimiter [] = " " ;
char *Token;
string Assambler ;
char NOP [] = "nop";
//Main


int main ()
{
cin.getline(Code,1024,'%');

Token = strtok(Code, delimiter);

while (Token != NULL)
{
Token = strtok(NULL, delimiter);
if(strcmp(Token,NOP) == 0)
{
cout << "nop" << endl;
}
}
cout << Assambler << endl;
cin.get();


}


sry for my bad englisch, im german ...
Token = strtok(NULL, delimiter); may setToken to NULL, then
if(strcmp(Token,NOP) == 0) will dereference a NULL pointer.

1
2
3
4
5
6
7
8
9
10
int main()
{
    cin.getline(Code, 1024, '%') ;
    while ( (Token = strtok(Code, delimiter)) != NULL )
        if ( strcmp(Token, NOP) == 0 )
            cout << "nop\n" ;

    cout << Assambler << endl ;
    cin.get() ;
}
Last edited on
thx
Topic archived. No new replies allowed.