我正在創建一個帶有簡單文本解析器的RPG,並且我仍然在編寫文本解析器中存在違規的acces時遇到問題。這是我到目前爲止的代碼:0xC0000005:訪問衝突讀取位置0x00000000。 C++ vs2015
/*
Author: Michael Norris
Program: Generiquest
Filename: TextParser.cpp
Maintainence Log:
10/28/2015 Created textParser.cpp
Notes:
This text parser is fairly inefficient, but is easier to manage and understand for beginners.
*/
#include <conio.h>
#include <stdio.h>
#include <Windows.h>
#include <time.h>
#include "myheader.h"
#include <iostream>
#include <string.h>
using namespace std;
class Words
{
public:
Words()
{
word verbs[30];//This is an array of all the verbs
strcpy(verbs[0].text, "Items");
strcpy(verbs[1].text, "Stats");
strcpy(verbs[2].text, "Use");
strcpy(verbs[3].text, "Eat");
strcpy(verbs[4].text, "Throw");
strcpy(verbs[5].text, "Drop");
strcpy(verbs[6].text, "Look");
strcpy(verbs[7].text, "Move");
strcpy(verbs[8].text, "Put");
strcpy(verbs[9].text, "Speak");
strcpy(verbs[10].text, "Attack");
strcpy(verbs[11].text, "Go");
strcpy(verbs[12].text, "Climb");
strcpy(verbs[13].text, "Open");
strcpy(verbs[14].text, "Take");
strcpy(verbs[15].text, "Put");
strcpy(verbs[16].text, "Kill");
strcpy(verbs[17].text, "Get");
strcpy(verbs[18].text, "LOL");
//End of verb declarations
for (int ele = 0; ele < 19; ele++)
{
verbs[ele].type = verb;
}
}
};
Words mainWords;
void textParser()
{
char str[51] = "Test String";
char test[50] = "";
char word1[20] = "";
//char * word2;
char word3[20] = "";
char word4[20] = "";
system("cls");
scanf("%50[0-9a-zA-Z ]", &test);
flushall();
strcpy(word3, strtok(test, " ,.-"));
int cray;
for (bool correctI = false; correctI == false;)
{
if (word3 != NULL)
{
strcpy(word1, strtok(NULL, " ,.-"));
cray = strcmp(word1, NULL);//Error thrown here
if (cray != 0)
{
strcpy(word4, word1);
}
}
printf("%s", word3);
printf("%s", word4);
cray = stricmp(word1, "Items");
if (cray = 0)
{
printf("Success!!");
}
else
{
printf("Fail");
}
}
_getch();
}
//TODO: use stricmp()
我乳寧進在文本分析器功能的麻煩。
郵政相關的代碼在這裏,清楚地表明你的調試器說,如果知道的話會導致錯誤,以及相關變量的值就行了。 –
對您的結局做一些初步調查併發布相關代碼片段。添加的鏈接有100行代碼。 – Nandu
修正了這個問題 – NotSanley