1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
static int getrand ( int min , int max );
char check ( char it[256]);
int main ()
{char str[256],str2[256], copy1[256];
int i, a;
char c;
srand ( time ( 0 ) ) ;
for ( i = 0 ; i < 40 ; ++i )
str[i] = getrand ( 'A' , 'Z' ) ;
str[i] = '\0' ;
printf ( "%s\n" , str ) ;
do{
strcpy_s (copy1,str);
printf ( "Enter the letters you'd like to change: \n" ) ;
fflush ( stdout ) ;
gets_s ( str2 ) ;
while ( 0 == (check (str2)) )
{
printf ( "Must be between 2 to 20\nEnter again: " );
gets_s ( str2 ) ;
}
printf ( "Enter the character you'd like to change it to: \n" ) ;
fflush ( stdout ) ;
c = getchar ( ) ;
printf ("string s1 = {%s}\n", str);
printf ("string s2 = {%s}\n", str2);
printf ("character c = {%c}", c);
printf ("\n");
for ( i = 0 ; i < 4 ; ++i )
if ( strchr ( str2 , copy1[i] ) != NULL )
copy1[i] = c ;
printf ( "filtered s1 = {%s}\n" , copy1 ) ;
fflush ( stdout ) ;
printf ( "Do you want to repeat, press N/n for no, or press any key to repeat: " ) ;
fflush (stdin);
a = getchar ( );
printf ( "---------------------------------------... );
fflush (stdin);
if ( (a == 'N') || (a == 'n') )
{
return 0;
}
}while ((a != 'N') || (a != 'n') );
}
static int getrand ( int min , int max )
{
return rand ( ) % ( max - min + 1 ) + min ;
}
char check ( char it[256] )
{
int const lenmax=20, lenmin=2;
if (((strlen(it)) > lenmax)||((strlen(it)) < lenmin))
return 0 ;
}
|