Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void mistura(){
- int i=0, p=0;
- char a[30], b[30];
- char c[30];
- gets(a);
- gets(b);
- for (i=0;i<strlen(a);i++)
- {
- if (p==0){
- c[i]=a[i];
- p=1;
- }
- else if (p==1){
- c[i]=b[i];
- p=0;
- }
- }
- puts(c);
- }
- void ocorrencias(){
- int i=0, x=0, j=0;
- char a[100];
- char p[30];
- char *pch;
- gets(a);
- gets(p);
- pch = strstr(a,p);
- while (pch!=NULL){
- x++;
- strncpy(pch,"---",3);
- pch=strstr(a,p);
- }
- printf("%d",x);
- }
- int main(){
- int op=0;
- do{
- printf("1 - Mistura de strings\n");
- printf("2 - Numero de ocorrencias na string\n");
- printf("3 - Sair\n");
- scanf("%d",&op);
- switch(op){
- case 1: mistura();
- break;
- case 2: ocorrencias();
- break;
- }
- }while (op != 3);
- return 0;
- }
Add Comment
Please, Sign In to add comment