打印字符串中第一个只出现一次的字符(C语言)

闲着没事,同事出了一道题目,RT,第一次没做对,在这里做个记录。

 1  void find(const char* s)
 2  {
 3       int array[256] = {0};
 4       char* p = s;
 5   
 6       //按顺序计数s中的每个字符
 7       while(*p)
 8       {
 9           array[*p++]++;
10       }
11  
12      //找出只出现一次的第一个字符
13      while(*s && (array[*s] != 1))
14      {
15 s++;
16 } 17 printf("%c\n",*s); 18 }

简单运行一下:

http://codepad.org/sgZk1JC2

好久不碰c了,看见指针还是那么头疼。囧

 

原文地址:https://www.cnblogs.com/pkray/p/2875781.html