BlueBear icon

stringy.c

BlueBear | PRO | 03/19/13 09:22:14 PM UTC | 0 ⭐ | 468 👁️ | Never ⏰ | []
C |

1.62 KB

|

None

|

0 👍

/

0 👎

/*
    xnagyl2.c
    ZPPLS13
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define MAX_STR 50
 
void strinsert(char *s, int d, char *s2, int i);
void strdelete(char *s, int i, int n);
 
 
int main()
{
    char s[MAX_STR] = "";
    char s2[MAX_STR] = "";
    char vyber;
    int i, n, d, len;
 
    while(vyber = getchar())
    {
        if(vyber == 'N')
        {
            scanf("%s", &s);
            printf("%s",s);
        }
        else if(vyber == 'V')
        {
            scanf("%d %s", &i, &s2);
            len = strlen(s2);
            strinsert(s, len, s2, i);
            printf("%s",s);
        }
        else if(vyber == 'Z')
        {
            scanf("%d %d", &i, &n);
            strdelete(s, i, n);
            printf("%s\n",s);
        }
        else if(vyber == 'K')
        {
            break;
        }
    }
    return 0;
}
 
 
void strinsert(char *s, int d, char *s2, int i)
{
    int len;
    char *str;
    str = (char *)malloc(d * sizeof(char));
    len = strlen(s);
    if(len == 0 || MAX_STR < len + d)
    {
        printf("do retazca nie je mozne vlozit podretazec od zvolenej pozicie\n");
        return;
    }
    strncpy(str, s, i);
    str[i] = '\0';
    strdelete(s, 0, i);
    strcat(str, s2);
    strcat(str, s);
    strcpy(s, str);
}
 
void strdelete(char *s, int i, int n)
{
    int j;
    int len;
    len = strlen(s);
    if(i+n > len || len == 0)
    {
        printf("z retazca nie je mozne vymazat znaky\n");
        return;
    }
    for(j=i; j<len; j++)
    {
        s[j] = s[j+n];
    }
 
    s[len+1-n] = '\0';
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  • Syutrsz icon
    03/31/26 11:00:32 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎