Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int Controllo (int, char *, char*);
- void Taglia (int, int, char*);
- int main () {
- int i, j, continua = 1;
- char c, stringa[40], sotto[40];
- printf("Inserisci testo libero (\n per terminare) > ");
- gets(stringa);
- printf("Inserisci token da eliminare > ");
- gets(sotto);
- stringa[strlen(stringa)] = '\0';
- while(continua){
- for (i=0; i<strlen(stringa); i++)
- {
- continua = 0;
- if (stringa[i] == sotto[0]){
- int elimina = Controllo(i, stringa, sotto);
- if (elimina){
- continua = 1;
- Taglia(i, strlen(sotto), stringa);
- i --;
- }
- }
- }
- }
- printf("%s", stringa);
- }
- int Controllo (int pos, char* stringa, char* sotto)
- {
- int analisi;
- int j;
- analisi = strlen(sotto);
- for (j=0; j<analisi; j++)
- {
- if (stringa[pos + j] != sotto[j])
- return 0;
- }
- return 1;
- }
- void Taglia(int pos, int len, char *stringa){
- int j;
- for (j=0; j<(strlen(stringa) - pos); j++){
- stringa[j + pos] = stringa[j + pos + len];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement