Skip to content

Instantly share code, notes, and snippets.

@rpt
Forked from rpt/1_2005.c
Created June 1, 2010 20:22
Show Gist options
  • Save rpt/421428 to your computer and use it in GitHub Desktop.
Save rpt/421428 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
int strfindandblank( char *source, char *find ) {
int ile = 0;
int find_size = strlen(find);
char *pch;
pch = strstr(source, find);
while(pch!=NULL) {
memset(pch, ' ', find_size);
ile += find_size;
pch = strstr(source, find);
}
return ile;
}
/**
* Funkcja zamieniajaca pierwszy znaleziony enter na koniec stringa.
*/
void strip(char *str) {
int i;
for(i=0; i<strlen(str); i++)
if(str[i] == '\n') {
str[i] = '\0';
break;
}
}
int main() {
char source[1024];
char find[1024];
printf("Podaj ciag znakow: ");
fgets(source, 1024, stdin);
strip(source);
printf("Podaj szukana fraze: ");
fgets(find, 1024, stdin);
strip(find);
printf("Zamieniono na spacje %i znakow.\n", strfindandblank(source, find));
printf("Napis wyglada teraz tak: %s\n", source);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment