字符串数组中查找字符串
生活随笔
收集整理的這篇文章主要介紹了
字符串数组中查找字符串
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
# include <stdio.h>
# include <string.h>
int search(char* p[], char* name);
/* 給字符型的指針數組賦初值 */
char* names[] = {
?"Herb",
?"Rex",
?"Dennis",
?"John",
?NULL};??? /* NULL指針標志數組內容的結束 */
?
void main()
{
?if(search(names, "Herb") != -1)
??printf("Herb is in list.\n");
?
??? if(search(names, "Mary") == -1)
??printf("Mary not found.\n");
}
?
int search(char* p[], char* name)
{
?register int t;
??
?for(t = 0; p[t]; ++t)
??if(!strcmp(p[t], name)) return t;
??? return -1;
}
總結
以上是生活随笔為你收集整理的字符串数组中查找字符串的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: bcb中使用pas文件
- 下一篇: c中的跳转