Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int len=0;
- char *arr;
- int mystrlen(char *s);
- int h;
- char **warr;
- char *my_strcat(char *str_one, char *str_two){
- while (*str_one){
- str_one++;
- }
- while(*str_two){
- *str_one=*str_two;
- str_one++;
- str_two++;
- }
- *str_one = '\0';
- return str_one;
- }
- char *links(char **C, int M){
- for(int j=0;j<=(M-1); j=(j+1)){
- len=(len+(((int)mystrlen(C[j])))+ 1);
- }
- arr=(char *)calloc((len),sizeof(char));
- if(0==arr){
- printf("Error");
- return 1;
- }
- arr[0]='\0';
- for(int k=0; k<=(M-1); k=(k+1)){
- strncat(arr,C[k],((mystrlen(C[k]))+1));
- }
- return arr;
- }
- int main(void){
- scanf("%d ", &h);
- char *w=0;
- warr=malloc(sizeof(char *) *h);
- if(0==warr){
- printf("Error");
- return 1;
- }
- for(int j=0; j<=(h-1); j=(j+1)){
- warr[j]= malloc(100*sizeof(char));
- if(warr[j] == 0){
- printf("Error ");
- return 1;
- }
- gets(warr[j]);
- }
- w=links(warr, h);
- printf("%s", w);
- printf("\n");
- for(int k=0; k<=(h-1); k=(k+1)){
- free(warr[k]);
- }
- free(warr);
- free(w);
- return 0;
- }
- int mystrlen(char *B){
- int m;
- for(m=0; B[m]; m++);
- return m;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement