C语言运行的时候汉字全部乱码怎么回事?

做一个系统加了下面这些以后汉字就开始乱码了
//删除函数void del(){ system("cls"); struct iphone *p,*temp; int x; temp=head; printf("请输入想要删除的销售人员代号\n"); scanf("%d",&x); while(temp->num!=x&&temp!=NULL) { p=temp; temp=temp->next; /* 跟踪链表的增长,即指针后移*/ } if(x==temp->num) /*找到相同人员代号*/ { if(temp==head) //要删除项在表头位置 { printf("\n删除代号是%d的销售人员信息\n",temp->num); head=head->next; //将结点从链表中删除 free(temp); //释放要删除结点 } else { p->next=temp->next; //结点在中间位置 printf("delete %d people\n",temp->num); free(temp); } } else printf("no find people");}

1、汉字乱码是因为缓冲区有字符,需要用fflush(stdin);来清空键盘缓冲区,
使用getch等都是治标不治本的办法,可以多学习一下fflush的使用,对于大批量的手动输入,很用。
2、例程:

#include"stdio.h"
#include"stdlib.h"
#include <conio.h>
main()
{   
    
    char x;
    while(1)
    {
        printf("请输入一个小写字母:");
            fflush(stdin);//清空键盘缓冲区
    x = getchar();
    printf("大写字母为:\n");putchar(x - 32);
    }
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-12-15
看你这图比较面熟,你是不是用的Code::Blocks? 如果是的话:
这是CodeBlocks编译器设置问题,在CodeBlocks菜单选择
Settings -> Compiler and debugger settings -> Global compiler settings -> Other options ,在其中输入语句
-fexec-charset=GBK -finput-charset=UTF-8追问

等会我再按你说的看一下,那为什么只有加了这个函数以后才会乱码?是不是函数有错误?谢啦,还有一个问题有一个函数老是出错,求解,我把图片发到问题补充里,靠你了大神

追答

if()条件里面的printf()函数不加取地址符&。

本回答被网友采纳
第2个回答  2014-01-12
else { p->next=temp->next; //结点在中间位置 printf("delete %d people\n",temp->num); free(temp); }

如果temp已经漂到尾结点,temp->next是位置的,就像一楼说的越界,所以最好做一个是否是末尾结点的判断,当为最后一个,直接删除free.
第3个回答  2014-01-12
(“” ; /n),可能少了一些符号?!
第4个回答  2014-01-12
越界访问了
相似回答