Task:
Write a function that adds the word in a sentence. The function has the following prototype:
void add (char * sentence, char * word);
Punctuation should be added immediately after the word. The function is necessary to dynamically
allocate memory needed to add a word.
In the main program, declare a pointer sentences and Dynamic Allocate enough memory
to enter 10 characters. Enter the word and call function add. Adding repeat until
load point.
Write a function that will remove the word from the sentences that are not anagrams, in a way that other signs
moves to the left. The function has the following prototype:
void remove (char * sentence);
In the main program call the function and display the newly created sentence.
Write a function that will change the order of words in a sentence (first and last word of changing place,
second and penultimate place for change, etc). The function has the following prototype:
void replace (char * sentence);
In the main program call the function and display the newly created sentence.
I managed to get to here:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void add(char *, char *);
void remove(char *);
void replace(char *);
int main(){
int i;
char word[20];
char *sentence;
sentence=(char *) calloc(10,sizeof(char));
do{
printf("Enter word, for stop enter '.' :\n");
scanf("%s", word);
add(sentence,word);
}while(strchr(sentence,'.')==0);
printf("%s",sentence);
remove(sentance);
printf("%s",sentence);
replace(sentance);
printf("%s",sentence);
return 0;
}
void add(char *sentence, char *word){
char space[2]=" ";
sentence=realloc(sentence,(strlen(sentence)+strlen(word)+1));
if(*sentence==0)
strcat(sentence,word);
else if(ispunct(word[0])==0){
strcat(sentence,space);
strcat(sentence,word);
}
else
strcat(sentence,word);
}
void remove(char *sentence){
}
void replace(char *sentence){
}
program: codeblocks
compiler: GNU GCC
I do not know how to solve functions remove and replace.
Thanks in advance!