为什么这不起作用? months [5] ==名字相等。 months[5]
为Jun
,name
为Jun
但if
永不执行...
int getMonthNum(char * name){
char *months[12] ={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
char *pointertoarray = &months;
int i;
for(i = 1; i <= 12; i++){
if(months[5] == name){
return i;
}
}
return i;
}
答案 0 :(得分:4)
使用strcmp,否则它将比较指针。
.box{
position: relative;
float: left;
width: 20%;
padding-bottom: 20%;
margin: 10px 0.5% 0px 0px;
background: #dd8;
border-radius: 7px;
}
.innerbox{
position: absolute;
top: 10px;
bottom: 10px;
right: 10px;
left: 10px;
overflow: hidden;
}
.innerbox img{
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="box">
<div class="innerbox">
<img src="image1.jpg" alt="">
<div class="title">Title here</div>
</div>
</div>
<div class="box">
<div class="innerbox">
<img src="image2.jpg" alt="">
<div class="title">Title here</div>
</div>
</div>
</body>
http://www.tutorialspoint.com/c_standard_library/c_function_strcmp.htm