so i did random generator of letters.
so i got s1=qwerty
then i imput " Character you want to change"
so i put s2=w
then i input " character you want to change it with"
so i put s3= $
....
so far all its doing is pulling out the characters that i do want to change and changes them, but the rest of the string is not there. the characters are gone.
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
|
#include <time.h>
#include <string.h>
#include <iostream>
#define MIN 0
#define MAX 25
int getrand(int min, int max);
int main(void) {
char s1[256], s2[256];
char string[256];
int p,c,i=0;
srand(time(NULL));
for(i; i<40; i++) {
p=getrand(MIN,MAX);
p=p+65;
putchar (p);
if ((p >= 'A') || (p <= 'Z'))
{
s1[i] = ("%c",p);
}
}
if (i == 40)
{
s1 [i] = '\0';
}
printf (" \n");
printf (" \n");
printf ("Enter a the letters youd like to change: ");
gets_s (s2);
printf ("Enter a the character youd like to change it to: ");
c = getchar ();
printf (" \n");
printf (" \n");
char * pch;
printf ("'%s' changed to:\n ",s1);
pch = strpbrk (s1, s2);
while (pch != NULL)
{
*pch = c;
printf ("%c " , *pch);
pch = strpbrk (pch+1,s2);
}
printf ("\n");
return 0;
}
int getrand(int min,int max){
return(rand()%(max-min)+min);
}
|
--------------------------------------...
as result i get:
LAOUHKJUSAALKMRBHJOJJQUCQPSNGFECXQGFKX...
Enter a the letters youd like to change: A
Enter a the character youd like to change it to: #
'LAOUHKJUSAALKMRBHJOJJQUCQPSNGFECXQGFK... changed to:
# # #
Press any key to continue . . .
***but its supposed to be
***'L#OUHKJUS##LKMRBHJOJJQUCQPSNGFECXQGFK'
*** but it wont budge!.
*** ive triend many functions, and i just cant get it anymore.