«Как исправить ошибку C4996:« _strupr »:« ошибка в C ++ » - PullRequest
0 голосов
/ 14 мая 2019

Я следую инструкциям, изменив strupr на _strupr и дай другую ошибку, затем я перейду на _strupr_s, но он сказал

тип аргумента char *

может кто-нибудь помочь?

// interpreter.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cctype>
#include "Interpreter.h"
using namespace std;

double Statement::findValue(char *id)   //Return the  value
{
IdNode tmp(id);
list<IdNode>::iterator i = find(idList.begin(), idList.end(), tmp);
if (i != idList.end())
    return i->value;
else
    issueError("unknown variable");
return 0;
}
void Statement::processNode(char *id, double e) //Update the value or add it to the list
{
IdNode tmp(id, e);
list<IdNode>::iterator i = find(idList.begin(), idList.end(), tmp);
if (i != idList.end())
    i->value = e;
else
    idList.push_front(tmp);
 }
 void Statement::readId(char *id)  //Read input into an array
{
int i = 0;
if (isspace(ch))
    cin >> ch;
if (isalpha(ch)){ //If it is a letter, save the subsequent numbers or letters.
    while (isalnum(ch)){
        id[i++] = ch;
        cin.get(ch);
    }
    id[i] = '\0';
}
else
    issueError("Identifier expected");
}
double Statement::factor()  //Factor processing
{
double var, minus = 1.0;
static char id[200];
cin >> ch;
while (ch == '+' || ch == '-'){ //Is the symbol before the number
    if (ch == '-')   //Determine positive and negative
        minus *= -1.0;
    cin >> ch;
}
if (isdigit(ch) || ch == '.'){   //number
    cin.putback(ch);
    cin >> var >> ch; //save vaule
}
else if (ch == '('){ //Equal to the left parenthesis to handle the expression inside the parentheses
    var = expression(); //Recursively processing expressions in parentheses
    if (ch == ')')   //The right parenthesis continues to process ch
        cin >> ch;
    else
        issueError("right paren left out");
}
else{
    readId(id);
    if (isspace(ch))
        cin >> ch;
    var = findValue(id);
}
return minus * var;
}
double Statement::term()
{
double f = factor();
while (true){
    switch (ch){
    case '*':
        f *= factor();
        break;
    case '/':
        f /= factor();
        break;
    default:
        return f;
    }
  }
 }
double Statement::expression()
{
double t = term();
while (true){
    switch (ch){
    case '+':
        t += term();
        break;
    case '-':
        t -= term();
        break;
    default:
        return t;
    }
}
}
void Statement::getStatement()
{
char id[20];
char command[20];
double e;
cout << "enter a statement: ";
cin >> ch;
readId(id);
_strupr_s(strcpy(command, id));
if (strcmp(command, "STATUS") == 0)
    cout << *this;
if (strcmp(command, "PRINT") == 0){
    readId(id);
    cout << id << " = " << findValue(id) << endl;
}
else if (strcmp(command, "END") == 0)
    exit(0);
else{
    if (isspace(ch))
        cin >> ch;
    if (ch == '='){
        e = expression();
        if (ch != ';')
            issueError("there are some extras in the statement. ");
        else
            processNode(id, e);
    }
    else
        issueError("'=' is missing");
}
}
ostream &operator<<(ostream &out, const Statement &s)
{
list<IdNode>::const_iterator i = s.idList.begin();
for (; i != s.idList.end(); i++)
    out << *i;
out << endl;
return out;
}
ostream &operator<<(ostream &out, const IdNode &r)
{
out << r.id << " = " << r.value << endl;
return out;
}

int main()
{
Statement statement;
cout << "the program processes statements  of the following format:\n"
    << "\t<id> = <expr>;\n\tprint <id>\n\tstatus\n\tend\n\n";
while (true)
    statement.getStatement();

return 0;
}


// TODO: reference additional headers your program requires here

1 Ответ

0 голосов
/ 14 мая 2019

Согласно документации , _strupr_s определяется как:

errno_t _strupr_s(
   char *str,
   size_t numberOfElements
);

Ваш код вызывает функцию как:

_strupr_s(strcpy(command, id));

Вы уходитевторой аргумент: size_t numberOfElements

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...