我正在尝试用数组实现堆栈!每次我执行程序时都运行良好,但我收到警告,因为默认情况下忽略空字符
这个警告是什么意思?..我做错了什么?
我的代码是:
#include<stdio.h>
#include<stdlib.h>
# define MAX 10
int top=-1;
int arr[MAX];
void push(int item)
{
if(top==MAX-1)
{
printf("OOps stack overflow:\n");
exit(1);
}
top=top+1;
arr[top]=item;
}//warning
int popStack()
{
if(top==0)
{
printf("Stack already empty:\n");
exit(1);
}
int x=arr[top];
top=top-1;
return x;
}
void display()
{
int i;
for(i=top;i>=0;i--)
{
printf("%d ",arr[i]);
}
return;
}
int peek()
{
if(top==-1)
{
printf("\nEmpty stack");
exit(1);
}
return arr[top];
}
int main()
{
int i,value;
printf(" \n1. Push to stack");
printf(" \n2. Pop from Stack");
printf(" \n3. Display data of Stack");
printf(" \n4. Display Top");
printf(" \n5. Quit\n");
while(1)
{
printf(" \nChoose Option: ");
scanf("%d",&i);
switch(i)
{
case 1:
{
int value;
printf("\nEnter a value to push into Stack: ");
scanf("%d",&value);
push(value);
break;
}
case 2:
{
int p=popStack();
printf("Element popped out is:%d\n",p);
break;
}
case 3:
{
printf("The elements are:\n");
display();
break;
}
case 4:
{
int p=peek();
printf("The top position is: %d\n",p);
break;
}
case 5:
{
exit(0);
}
default:
{
printf("\nwrong choice for operation");
}
}
}
return 0;
}//warning
我正在使用 Dev C++ IDE。
最佳答案
如果您看到大量此类空字符警告,请考虑以下情况。该问题可能是由于某人使用将文件另存为 16 位 Unicode 的编辑器创建源文件引起的。
要解决这个问题(在 Linux 上)不需要十六进制编辑器。只需在 geany 编辑器中打开文件(其他编辑器也可能也支持)检查文件属性以查看编码,如果它是 UTF/UCS 16,则可以在文档菜单中将其更改为 UTF8。如果也有 BOM,那么删除 BOM 可能是值得的。
在这种情况下,错误是意料之中的,因为 ASCII 范围内字符的 UCS16 编码将使每个第二个字节成为空字符。
关于c - 默认启用忽略空字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17222397/