В переполнении стека произошло переполнение буфера

Эта программа получит строку (char Array) математического выражения от пользователя и проанализирует ее, а затем сохранит каждую часть (числа и операторы отдельно) в элементе массива с именем exp. Я раньше отлаживал эту программу в c #, и она работала довольно правильно, но теперь, когда я изучаю C ++ в колледже, я должен программировать на этом языке, поэтому, когда я отлаживаю эту программу в visual studio, я получаю сообщение об ошибке:

«В LineCalculator.exe произошло переполнение буфера, которое повредило внутреннее состояние программы. Нажмите« Разрыв », чтобы отладить программу, или« Продолжить », чтобы завершить программу.»

пожалуйста, помогите, что мне делать?

#include "stdafx.h"#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <math.h>
using namespace std;

struct str{
char text[10];
};
void input();
void CurrentObs(char source[],char current , int i,str exp[],int c,int ExpNum);
void ExpAssign(int i ,int c , int ExpNum,char current ,char source[],str exp[]);
int _tmain(int argc, _TCHAR* argv[])
{
input();
return 0;
}
void input()*//for getting the string from the user*
{
char source[50];
gets(source);
struct str exp[20];
int i=-1;
int c=0;
int ExpNum=-1;
do{
i++;
char current=source[i];
CurrentObs(source,current,i,exp,c,ExpNum);
}while(i<50);
//the next loop will print the parsed expressions in separate lines
for(int b=0;b<20;b++)
cout<<exp[b].text<<endl;
}
//the next function is to check if the current character is one of the signs mentioned in the signs array or not
void CurrentObs(char source[],char current , int i,str exp[],int c,int ExpNum)
{
struct str signs[7]={"+","-","/","*","=","(",")"};
for (int x=0;x<7;x++)
if (current==*signs[i].text)
{
ExpNum++;
ExpAssign(i,c,ExpNum,current,source,exp);
break;
}
}
void ExpAssign(int i ,int c , int ExpNum,char current ,char source[],str exp[])
{
char parsed[10];
for (int j = c; j < i; j++)
parsed[j-c]=source[j];
strcpy(exp[ExpNum].text,parsed);
c=i+1;

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector