Print first non duplicate Character from String.

Code Snippets 4 U
#include < stdio.h > 
#include < stdlib.h > 
#include < string.h >
  int main() {
    char * str = "ii I am Good and Printing Not Duplicate";
    // for ASCII characters only
    static int strCount[256];

    for (int i = 0; i < strlen(str) - 1; i++) {
      int repeated = 0;
      for (int j = i + 1; j < strlen(str); j++) {
        if (str[i] == str[j]) {
          repeated++;
          break;
        }
      }
      if (repeated == 0) {
        printf("%c", str[i]);
        break;
      } else continue;
    }

    return 0;
  }

Leave a Reply

Your email address will not be published. Required fields are marked *

− two = four