我正在为学校做作业,我似乎对数组中的其他字符有疑问。(在其他问题中......)
在一个函数中,我声明了数组..
const int MAXSIZE = 100;
char inFix[MAXSIZE];
这段代码用于将字符放入数组
//loop to store user input until enter is pressed
while((inputChar = static_cast<char>(cin.get()))!= '\n')
{
//if function to decide if the input should be stored or not
if(isOperator(inputChar) || isdigit(static_cast<int>(inputChar)) || inputChar == '(' || inputChar == ')')
{
inFix[a] = inputChar; //stores input
a++;
}
}
最后,我将空字符附加到数组中,尽管我不确定是否应该这样做:
inFix[MAXSIZE] = '\0';
或者如果我应该使用strcat
.. 无论哪种方式......在我的下一个函数中,我使用 strcat 在末尾附加一个括号。
但是我的代码一直有问题,所以我运行了一个 for 循环来打印下一个函数开头的中缀数组中的内容,只是为了看看......
我听到了这种烦人的哔哔声,还有一串奇怪的字符,比如心形、音乐符号……还有……一整串奇怪的字符。可能是什么问题呢?谢谢。
编辑:顺便说一句,我输入9*4
,并在附加括号后运行 for 循环,所以在输出的开头,我得到:
9*4)
然后是一串奇数字符...