Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C-进程已退出,错误代码为3221225477_C_Windows_Shift Reduce - Fatal编程技术网

C-进程已退出,错误代码为3221225477

C-进程已退出,错误代码为3221225477,c,windows,shift-reduce,C,Windows,Shift Reduce,我正在为我们的编译器设计主题做一个移位减少算法。这是代码 void shiftReduce(char str[MAX_CHAR], int prodNum, int line) { int limit = 5, y=0; int substrFlag = 1; //0 true 1 false int ctr,x, counter; int match, next; char stack[MAX_CHAR]; clearString(stack);

我正在为我们的编译器设计主题做一个移位减少算法。这是代码

void shiftReduce(char str[MAX_CHAR], int prodNum, int line)
{
    int limit = 5, y=0;
    int substrFlag = 1; //0 true 1 false
    int ctr,x, counter;
    int match, next;
    char stack[MAX_CHAR];
    clearString(stack);
    OUTER:while ((strcmp(stack, prod[0].left) != 0) && (y < limit))
    {
        addChar(stack, str[0]);
        strcpy(str, dequeue(str));
        printf("Stack = %s\nQueue = %s\n", stack, str);
        for (ctr = 0; ctr < prodNum; ctr++)
        {
            if (strstr(stack, prod[ctr].right) != NULL)
            { //substring found
                substrFlag = 0;
                strcpy(stack, replace(stack, prod[ctr].right, prod[ctr].left));
                goto OUTER;
            }
        }
        if ((str[0] == '\n') || (str[0] == '\0'))
            y++;
    }
    if (strcmp(stack, prod[0].left) == 0)
        ;//printf("%s - Accepted.\n", stack);
    else
        printf("Syntax error on line %i\n", line);
}
和addChar函数:

void addChar (char * str, char letter)
{
    int a = 0;
    while (str[a] != '\0')
        a++;
    str[a] = letter;
    str[a+1] = '\0';
    return;
}
最后替换函数

char * replace (char orig[MAX_CHAR], char substr[MAX_CHAR], char rep[MAX_CHAR])
{
    int match, end=0, next=0;
    int flag = 0; //0 true 1 false
    char temp [MAX_CHAR];
    char store[MAX_CHAR];
    if (strstr(orig, substr) == NULL)
        return NULL;
    int x,y;
    for (x = 0; x < length(orig); x++)
    { 
        if (orig[x] == substr[0]) //if current character  is equal to first character of substring
        {
            match = x;
            for (y = 0; y < length(substr); y++)
            { 
                if (orig[match+y] != substr[y])
                {
                    flag = 1;
                    break;  
                }
            }
            if (flag == 0)
            {
                next = match + length(substr);
                for (y = 0; y < length(rep); y++)
                { 
                    temp[match+y] = rep[y]; 
                    end = (match+y);
                }
                for (y = next; y < length(orig); y++)
                { 
                    temp[y] = orig[next+(y-next)];
                }
                return temp;
            }
        }
        else
        {
            addChar(temp, orig[x]);
        }
    }
    return temp;
}
当我注释
printf时(“Stack=%s\nQueue=%s\n”,Stack,str)行,它工作得很好。但是当我取消注释它时,它返回代码
322225477


然后很可能是
stack
str
未被
0
终止或指向无效内存。

“…它返回代码322225477…”您是什么意思?“Returns”在编程中有相当具体的含义,但您要问的函数是
void
。你的意思是它抛出了一个错误吗?
322225477
0xc000005
这是一个windows程序员非常熟悉的数字…;-)
char * replace (char orig[MAX_CHAR], char substr[MAX_CHAR], char rep[MAX_CHAR])
{
    int match, end=0, next=0;
    int flag = 0; //0 true 1 false
    char temp [MAX_CHAR];
    char store[MAX_CHAR];
    if (strstr(orig, substr) == NULL)
        return NULL;
    int x,y;
    for (x = 0; x < length(orig); x++)
    { 
        if (orig[x] == substr[0]) //if current character  is equal to first character of substring
        {
            match = x;
            for (y = 0; y < length(substr); y++)
            { 
                if (orig[match+y] != substr[y])
                {
                    flag = 1;
                    break;  
                }
            }
            if (flag == 0)
            {
                next = match + length(substr);
                for (y = 0; y < length(rep); y++)
                { 
                    temp[match+y] = rep[y]; 
                    end = (match+y);
                }
                for (y = next; y < length(orig); y++)
                { 
                    temp[y] = orig[next+(y-next)];
                }
                return temp;
            }
        }
        else
        {
            addChar(temp, orig[x]);
        }
    }
    return temp;
}
struct RULES
{
    char left[MAX_CHAR];
    char right[MAX_CHAR];
} RULES;
struct RULES prod[MAX_RULES];