0
int main()
{
   char arr[20], charo, cha;
   int len, score=0;
   printf("Enter the line: ");
   scanf("%[^\n]%*c", arr);
   printf("Enter the letter you want to search for: ");
   scanf("%c", &charo);
   printf("Enter the letter you want to exchange: ");
   scanf("%c", &cha);
   len = strlen(arr);
   for(int i=0; i<len; i++)
       if(arr[i] == charo)
           {
               arr[i] = cha;
           }
   for(int i=0; i<len; i++)
   {
       printf("%s", arr);
   }
}

I wanted to take a string as an input and then select a letter and replace that letter with another letter taken as an input from the user. But the third scanf doesn't work.

swat08
  • 1
  • 2
  • ```scanf``` leaves the ```newline ``` in the input buffer, which automatically gets read by subsequent calls to ot it it other input functions. As ```'\n'``` is a ```char```, it satisfies the third call to ```scanf```. – Harith Dec 15 '22 at 16:35

0 Answers0