默认情况下忽略null字符

use*_*862 5 c stack warnings

我正在尝试用数组实现堆栈!每次我执行程序运行正常,但我收到警告,因为默认情况下忽略了空字符

这个警告意味着什么?我做错了什么?

我的代码是:

#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
Run Code Online (Sandbox Code Playgroud)

我正在使用Dev C++ IDE.

bva*_*lew 14

如果您看到大量这些空字符警告,请考虑以下可能性.问题可能是由于某人使用将文件保存为16位Unicode的编辑器创建源文件引起的.

要修复它(在Linux上),不需要十六进制编辑器.只需在geany编辑器中打开文件(其他编辑器也可能也支持这个)检查文件属性以查看编码,如果它是UTF/UCS 16,则在文档菜单中可以将其更改为UTF8.如果有BOM,则可能值得删除BOM.

在这种情况下,错误是预期的,因为ASCII范围内的字符的UCS16编码将使每个第二个字节成为空字符.


nos*_*nos 10

在源代码文件的某处,您的字符值为0(ASCII NUL字符).这在大多数文本编辑器中都是不可见的.

编译器(gcc)只是告诉你它忽略了那个字符 - 这在你的源代码中确实不应该存在.

您可以在十六进制编辑器中打开文件,找出该角色的位置并进行修复,或者删除源文件并将其从您在此处发布的代码中复制粘贴回来.


Bur*_*ito 5

正如其他人所说,警告意味着您的源代码中有空字节。

例如,当您尝试在 Linux 中编译最初编写为 Windows 中的 Visual Studio 项目(默认情况下保存为 UTF-16)的代码时,可能会发生这种情况。由于 g++ 期望源文件为 UTF-8,因此它最终会读取空字节。

就我而言,最简单的解决方案是使用 iconv (Linux) 转换编码

iconv myfile -f UTF-16 -t UTF-8 > myfile
Run Code Online (Sandbox Code Playgroud)

您可以使用 file 检查文件的编码

file myfile
Run Code Online (Sandbox Code Playgroud)