Hey all,
I am having an issue here but i really don't understand what's happening. the code below asks the user to input a string and what letter does the user want to change and with what.
The problem is that from what i see it skips entirely my for loop and statement and doesn't print anything.
Please explain what's exactly happening and how can I fix that.
Code:
#include <stdio.h>
#define MAX 100
int main()
{
char str[MAX];
char let;
char let2;
int i;
printf("Enter String: ");
scanf("%s", str);
printf("Enter character you want to change: ");
scanf("%s", &let);
printf("Enter character you want to replace: ");
scanf("%s", &let2);
for (i=0; str[i]!='\0'; i++)
{
if (str[i] == let)
str[i] = let2;
}
printf("The new string is\n%s\n", str);
return 0;
}