Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. int main()
  5. {
  6. int size = 10;
  7. char *array = malloc(size*sizeof(char));
  8. int br=0,max=0,max_length=0;
  9. for(int i=0;scanf("%c", &array[i]) != EOF;i++)
  10. {
  11. //if(array[i] == '\n')br++;
  12. if(i>=10)
  13. {
  14. array = realloc(array,size+2);
  15. size+=2;
  16. }
  17. if(array[i]!='\n')
  18. {
  19. max_length++;
  20. }
  21.  
  22. else{
  23. br++;
  24.  
  25. if(max_length>max)
  26. {
  27. max = max_length;
  28. }
  29.  
  30. max_length = 0;
  31. }
  32. }
  33. //printf("\nBROI NOVI REDOVE: %d",br);
  34. //printf("max length: %d",max);
  35. char res_arr[br][max];
  36. int g=0,f=0;
  37.  
  38. for(int z=0;z<br;z++)
  39. {
  40. for(;array[g]!='\n';g++)
  41. {
  42. res_arr[z][f] = array[g];
  43. printf("\narr: %c",array[g]);
  44. printf("\nres: %c ",res_arr[z][f]);
  45. f++;
  46. }
  47. g++;
  48. f=0;
  49. }
  50.  
  51. for(int k=0;k<br;k++)
  52. {
  53. for(int x = 0; x<strlen(res_arr[k]);x++)
  54. printf("%c",res_arr[k][x]);
  55. }
  56.  
  57. free(array);
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement