Advertisement
Jkljk

troca de caracteres em strings

Jun 23rd, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. /*Escreva um programa que pede ao usuário digitar uma string S e dois caracteres X e
  2. Y e troque todas as ocorrências de X em S por Y*/
  3. #include <stdio.h>
  4. #include <string.h>
  5. #define tam 10
  6. int main(){
  7. char s[tam], x, y;
  8. int i;
  9. printf("\nEscreva uma string:\n");
  10. fgets(s,tam,stdin);
  11. printf("\nInforme o caractere x\n");
  12. scanf("%c",&x);
  13. printf("\nInforme o caractere y\n");
  14. scanf("%c",&y);
  15. for(i=0;i<tam;i++){
  16.     if(tolower(s[i])=='x'){
  17.         s[i]=='y';
  18.     }
  19. }
  20. printf("\n %s",s[tam]);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement