"Disclaimer: This article is limited to self-summary and mutual exchange, there are flaws also hope you point out." Contact e-mail: [Email protected] "
Title: finds the first occurrence of a character in a string. If you enter Abaccdeff, then output B.
Topic Analysis:
One, no complexity requirements
Second, the sequential traversal of the string, and then each traversal of the resulting character, in the entire string lookup (note: To filter out the index of the current character)
Algorithm implementation:
#include <stdio.h> #include <string.h>/*** find @c in @str, it filters out the characters */char *str_chr (const char *STR, char C, int num) {int len = strlen (str), char *re = Str;int i=0; for (; i<len; i++) {if (i = = num) {re++;continue;} if (*re = = c) return re;re++;} return NULL;} Char find_once_char_in_str (const char *str) {int I=0;int len = strlen (str); for (; i<len; ++i) {if (STR_CHR (str, str[i], i) = = NULL) return str[i];} return 0;} int main () {char *str = "aabadccdebff7e";p rintf ("--->%c\n", Find_once_char_in_str (str)); return 0;}