text: Find repeated character present first in a string | C program to find the first character that is repeated ; this is O ( N ^ 2 ) method ; Driver code
code: #include <stdio.h> NEW_LINE #include <string.h> NEW_LINE int findRepeatFirstN2 ( char * s ) { int p = -1 , i , j ; for ( i = 0 ; i < strlen ( s ) ; i ++ ) { for ( j = i + 1 ; j < strlen ( s ) ; j ++ ) { if ( s [ i ] == s [ j ] ) { p = i ; break ; } } if ( p != -1 ) break ; } return p ; } int main ( ) { char str [ ] = " geeksforgeeks " ; int pos = findRepeatFirstN2 ( str ) ; if ( pos == -1 ) printf ( " Not ▁ found " ) ; else printf ( " % c " , str [ pos ] ) ; return 0 ; }