[C language] to delete duplicate characters in a string

#include <stdio.h>
 / * use n = add this #include <string.h> when strlen (S) * / 
int main ( void ) 
{ 
    char S [ 100 ]; / * define variables * / 
    int I, J , n-, K; 
    the printf ( " Please enter a string of the string of repeated characters: \ n- " ); 
    gets_s (S); / * input string * / 
    for (n-= 0 !; S [n-] = ' \ 0 ' ; n-++); / * for obtaining the length of the string, may be used strlen = n-(S); * / 
    for (I = 0 ; I <n-- . 1 ; I ++ ) 
    {
        for (J = K = I + . 1 ; J <n-- . 1 ; J ++ )
             IF (! S [J] = S [I]) 
                S [K ++] = S [J]; 
        S [K] = ' \ 0 ' ; 
    } 
    the printf ( " after eliminating the repeating character of the result is: \ n- " ); 
    the puts (S); 
    / * can write this, printf ( "after the removal of repeated characters results:% s \ n", s ); * / 
}  

 

Guess you like

Origin www.cnblogs.com/HGNET/p/11966034.html