C code


SUBMITTED BY: bitcoinsachen

DATE: Oct. 26, 2016, 6:52 p.m.

FORMAT: C

SIZE: 1.8 kB

HITS: 950

  1. long *allocate_numberarray(long len)
  2. {
  3. long *neuezahl;
  4. long n;
  5. if((neuezahl=malloc(len+sizeof(long)))!=0)
  6. {
  7. for(n=0; n<len; n++)
  8. neuezahl[n]=0;
  9. }
  10. else
  11. {
  12. printf( "0x1^Fehler bei allozierung\n");
  13. // fprintf(stderr, "0x1^Fehler bei allozierung\n"); //Fehler stderr ist nicht definiert ?
  14. exit(-1);
  15. }
  16. return &neuezahl[0];
  17. }
  18. void our_free(long *mem)
  19. {
  20. if(mem)
  21. {
  22. free(mem);
  23. mem=0;
  24. }
  25. }
  26. void print(long *mem, long len)
  27. {
  28. long n=len-1;
  29. printf("Die Zahl : ");
  30. for(; n>=0; n--)
  31. {
  32. printf("%ld", mem[n]);
  33. }
  34. printf("\n--------");
  35. }
  36. long *change_numberarray(long *mem, long len)
  37. {
  38. long n;
  39. long wert;
  40. printf("Zahl einlesen:");
  41. for(n; n<=len; n++)
  42. {
  43. if(mem[n]==0)
  44. {
  45. printf("%ld.Stelle:", len-n);
  46. scanf("%ld",&wert);
  47. getchar();
  48. mem[n]=wert;
  49. }
  50. }
  51. return &mem[0];
  52. }
  53. long *change_size(long *mem, long old_size, long new_size)
  54. {
  55. long *neuezahl1;
  56. long n;
  57. if ((neuezahl1 = realloc(mem,new_size*sizeof(long)))!=0)
  58. {
  59. if(new_size>old_size)
  60. {
  61. for(n=old_size; n<new_size; n++)
  62. {
  63. neuezahl1[n]=0;
  64. }
  65. }
  66. }
  67. else
  68. {
  69. printf("Fehler 0x2 Fehler bei der Reallozierung");
  70. exit(-2);
  71. }
  72. return &neuezahl1[0];
  73. }
  74. long add(long *a, long size1,
  75. long *b, long size2,
  76. long *c, long size3)
  77. {
  78. long n_a, n_b;
  79. for(n_a=0; n_a<size1; n_a++)
  80. c[n_a]=a[n_a];
  81. for(n_b=0; n_b<size2; n_b++)
  82. c[n_b]=c[n_b]+b[n_b];
  83. if(c)
  84. return 1;
  85. else
  86. return -1;
  87. }

comments powered by Disqus