Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define MAXCHRS 5
- #define MAXTEXT 200
- void inline clearbuffer()
- {
- while (getchar() != '\n');
- return;
- }
- char doreplace(char chr, char *search, char *replace)
- {
- char *search_tmp;
- if(search_tmp=strchr(search,chr))
- {
- return *(search_tmp-search+replace);
- }
- return chr;
- }
- int getline(char *query, char *str, int num)
- {
- char chr, *str_bak = str;
- printf("%s (%d ZEICHEN)\n", query,num);
- printf("S: ");
- while (666)
- {
- memset(str,0,num-1);
- while (( chr=getchar() )!='\n')
- {
- if (str>=str_bak+num)
- {
- printf("*** MAXIMAL %d ZEICHEN ERLAUBT ***\nS: ", num);
- str=str_bak;
- clearbuffer();
- break;
- }
- *str=chr;
- str++;
- }
- if (!(str==str_bak))
- {
- str=str_bak;
- return strlen(str);
- }
- }
- }
- int main()
- {
- char search[MAXCHRS+1], repl[MAXCHRS+1], text[MAXTEXT+1], *tmp;
- getline("SUCHEN",search, MAXCHRS);
- do
- {
- getline("ERSETZEN",repl, MAXCHRS);
- }
- while( strlen(search)!=strlen(repl) );
- getline("TEXT",text,MAXTEXT);
- tmp=text;
- printf(" ");
- while(*tmp)
- {
- putchar(doreplace(*tmp,search,repl));
- tmp++;
- }
- putchar('\n');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement