Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include "stdlib.h"
- #include <string.h>
- typedef struct rule1{
- char *a;
- char *b;
- }ru1;
- typedef struct rule2 {
- char *a;
- char *b;
- }ru2;
- int main(){
- int k = 0;
- ru1 r1;
- r1.a = (char*)malloc(1 * sizeof(char)); r1.a = "A";
- r1.b = (char*)malloc(2 * sizeof(char)); r1.b = "AB" ;
- ru2 r2;
- r2.a = (char*)malloc(1 * sizeof(char)); r2.a = "B";
- r2.b = (char*)malloc(1 * sizeof(char)); r2.b = "A";
- char *sentence=(char*)malloc((k+1) * sizeof(char));
- sentence = "A";
- char *nextSentence ;
- char*ns;
- for (int i = 0; i < strlen(sentence);++i)
- {
- char current = sentence[i];
- if (current == r1.a)
- {
- k++;
- strcat(nextSentence, r1.b);
- }
- else if (current == r2.a)
- {
- strcat(nextSentence, r2.b);
- }
- sentence = (char*)realloc(sentence, (k + 1) * sizeof(char));
- sentence = nextSentence;
- }
- printf("%s\n", sentence);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement