Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- #include <process.h>
- #include <string.h>
- int get_word(char*s,int *pos,char*w){
- int n=strlen(s);
- int i=0;
- while (*pos<n &&s[*pos]<=' ' ){
- ++*pos;
- }
- while (*pos<n &&s[*pos]>' ' ){
- w[i]=s[*pos];
- i++;
- ++*pos;
- }
- w[i]='\0';
- return i;
- }
- void SetWord(char s[20], char *a){
- int i = 0;
- while( s[i] != '\0' ){
- a[i] = s[i];
- i++;
- }
- a[i] = '\0';
- }
- void write_arr_str(char *text, char **t, int *n){
- int i = 0;
- char word[20] = {};
- while( text[i] != '\0'){
- int length = get_word(text,&i,word);
- t = (char**)realloc(t, (*n+1)*sizeof(char*));
- t[*n] = (char*)calloc(length, sizeof(char));
- SetWord(word,t[*n]);
- ++*n;
- }
- }
- int main() {
- char text1[] = {"vfd fvdvv df vf v dfv f d"};
- char text2[] = {" Hello Hello world! world! yes or no? Hello Hello world world You friend? aaa Or no?"};
- char **t1 = NULL;
- char **t2 = NULL;
- int n = 0;
- write_arr_str(text1,t1,&n);
- printf("\n");
- for(int i = 0; i < n; i++){
- puts(t1[i]);
- free(t1[i]);
- }
- free(t1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement