字符串第一個重複出現的字符

//找出一個字符串中第一個重複出現的字符

#include <stdio.h>
#include <stdlib.h>
#include <string.h>//memset
#include <memory.h>
#include <iostream>
#define N 256

char Find(char str[], int n)
{
char temp[N] = {0};
char dst;
//memset((void *)temp,0x00,N*sizeof(char));


for(int i=0; i < n; ++i)
{
int num = (int)str[i];
if(temp[num] == 0)
{
temp[num] = num;
}
else
{
dst = temp[num];
//std::cout << dst ;
break;
}
}
return dst;
}


void main()
{
char s[]="abcdefefddaddf";
//char ch;
char a =Find(s,sizeof(s)/sizeof(char));
std::cout << a;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章