Hi,

I'm new to this site so apologies for any mistakes. I'm trying to write a program to parse string from a file. In each string I then have to parse the different strings for example:

add h'13', 4

So I've to parse the 'add' bit, the '13' bit and the '4' bit. At the minute I'm trying to use strtok but I'm getting a run time error.

/* Libraries */
#include <stdio.h>
#include <string.h>

/* Main Function */
int main()
{
	/* Declarations */
    char *instruction;
    char *action;
    char *number;
    char *number2;
    
    instruction = "add  h'13', 4";
    
    printf("%s \n",instruction);

// The run time error occurs here

    action = strtok ( instruction, " " );
    number = strtok ( NULL, " ' " );
number2 = strtok ( NULL, "," );

	printf("%s \n %s \n %s \n", action, number, number2);

	system("PAUSE");
	return 0;
}

Any help you can give me would be greatly appreciated. Thanks.

Edited 7 Years Ago by pmee: n/a

Try defining your string "instruction" like below...
Also if you have errors in the future could you post them

/* Libraries */
#include <stdio.h>
#include <string.h>

char instruction[] = "add  h'13', 4";//not a constant now

/* Main Function */
int main()
{
	/* Declarations */
    
    char *action;
    char *number;
    char *number2;
    
    printf("%s \n",instruction);

// The run time error occurs here

    action = strtok ( instruction, " " );
   number = strtok ( NULL, " ' " );
number2 = strtok ( NULL, "," );

	printf("%s \n %s \n %s \n", action, number, number2);

	system("PAUSE");
	return 0;
}

Edited 7 Years Ago by gerard4143: n/a

This question has already been answered. Start a new discussion instead.