Ok, I did not convert this into a recursive funtion yet, mainly because I am running into an odd problem... Here is my new code, and below that is what is printing out.
Code:
#include<stdio.h>
#include<string.h>
#define SIZE 15
void replace_r(char *s, char c, char r)
{
char *p;
for (p=s; *p; p++) {
if (*p==c){
*p = r;
}
}
}
main()
{
char original_str[SIZE], s_char, r_char;
printf("Original word:");
fgets(original_str, SIZE, stdin);
printf("c(original character):");
scanf("%c", &s_char);
printf("r(replace character with):");
scanf("%c", &r_char);
replace_r(original_str, s_char, r_char);
printf("New Sentence: %s", original_str);
}
With this new code, I am receiving this result :
Code:
Original word:Hello
c(original character):H
r(replace character with):New Sentence:
ello
It looks like it wants to work, it makes sense that the H was removed... but why it won't let me enter my replace char is beyond me... I THOUGHT my replace function was correct.... any thoughts or fixes guys? thx.
**EDIT**
I figured out what the problem was... I needed to insert fflush(stdin); .... code now works and I just need to transform it into a recursive function.