Pedromaia26

Ex 3 string

Dec 4th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void mistura(){
  6.  
  7. int i=0, p=0;
  8. char a[30], b[30];
  9. char c[30];
  10. gets(a);
  11. gets(b);
  12. for (i=0;i<strlen(a);i++)
  13. {
  14. if (p==0){
  15. c[i]=a[i];
  16. p=1;
  17. }
  18. else if (p==1){
  19. c[i]=b[i];
  20. p=0;
  21. }
  22. }
  23. puts(c);
  24. }
  25.  
  26. void ocorrencias(){
  27. int i=0, x=0, j=0;
  28. char a[100];
  29. char p[30];
  30. char *pch;
  31. gets(a);
  32. gets(p);
  33. pch = strstr(a,p);
  34. while (pch!=NULL){
  35. x++;
  36. strncpy(pch,"---",3);
  37. pch=strstr(a,p);
  38. }
  39. printf("%d",x);
  40. }
  41.  
  42.  
  43.  
  44. int main(){
  45. int op=0;
  46. do{
  47. printf("1 - Mistura de strings\n");
  48. printf("2 - Numero de ocorrencias na string\n");
  49. printf("3 - Sair\n");
  50. scanf("%d",&op);
  51. switch(op){
  52. case 1: mistura();
  53. break;
  54. case 2: ocorrencias();
  55. break;
  56. }
  57. }while (op != 3);
  58. return 0;
  59. }
Add Comment
Please, Sign In to add comment