惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
罗磊的独立博客
H
Help Net Security
L
LangChain Blog
T
Threat Research - Cisco Blogs
量子位
S
Securelist
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
The Hacker News
The Hacker News
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
T
Threatpost
Security Latest
Security Latest
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
F
Full Disclosure
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Heimdal Security Blog
J
Java Code Geeks
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog RSS Feed
月光博客
月光博客
C
Cisco Blogs
V
Visual Studio Blog
D
DataBreaches.Net
H
Hacker News: Front Page
博客园 - 叶小钗
N
News and Events Feed by Topic
爱范儿
爱范儿
A
Arctic Wolf

博客园 - 萧佰刚

Mtk Ft6306 touch 驱动 . 深圳市鑫侑触控技术有限公司 电容式触摸屏|电容式触摸屏厂|手机触摸屏厂|偏光片贴合 Qt Creator 常用快捷键 结构体指针的指针使用(转) System V共享内存资料 "互斥锁用于上锁,条件变量则用于等待" Linux下UDP编程 Linux Socket编程学习 linux管道学习资料 linux进程间通信——消息队列 C实现单链表(转) c语言 位操作 指向结构体指针的例子 字符数组 字符指针 sizeof strlen 的区别 Linux进程间共享临界区“信号量”编程 Linux下Socket编程 Linux下常用函数- 信号处理函数(转) linux信号signal常用信号 Linux 守护进程的编程方法(转)
C语言枚举类型使用简介
萧佰刚 · 2011-05-27 · via 博客园 - 萧佰刚

1:枚举里面的值是常量;    例如 enum color {red,orange,yellow};

2:枚举列表中的常量默认为0,1,2等等  例如 enum color {red,orange,yellow};  常量值默认为0,1,2

3:  枚举列表常量值是可以指定的,且指定值后的枚举值将递增   例如enum color {red,orange=10,yellow}; yellow=11

4:  在C语言中枚举可以递增 运算符++,而C++中需要强制转换定义为int再运算符++

enum用法例子如下

#include<stdio.h>
#include<string.h>
enum  specturm {red,orange,yellow,green,blue,violet};
const char *colors[]={"red","orange","yellow","green","blue","violet"};
#define LEN 30
int main(void)
{
    
char choice[LEN];
    
int color;
    
int  color_is_found=0;
    puts("Enter a color (empty line to quit): ");
    
while(gets(choice)!=NULL&&choice[0]!='\0')
    {
        
for(color=red;color<=violet;color++)
        {
            
if(strcmp(choice,colors[color])==0)
            {
                color_is_found=1;
                
break;
            }
        }
        
if(color_is_found)
        
switch(color)
        {
            
case 0:puts("Roses are red");break;
            
case 1:puts("Poppies are orange");break;
            
case 2:puts("Sunflowers are yellow");break;
            
case 3: puts("Grass is green");break;
            
case 4:puts("Bluebells are blue");break;
            
case 5:puts("Violets are violet");break;
        }
        
else printf("I don't know about the color %s.\n",choice);
        color_is_found=0;
        puts("Next color,please(empty line to quit): ");
    }
    puts("Goodbye!");
    
return 0;
}