Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <stdbool.h>
  6.  
  7. int eat(long total,int chunk){
  8. long i;
  9. for(i=0;i<total;i+=chunk){
  10. short *buffer=malloc(sizeof(char)*chunk);
  11. if(buffer==NULL){
  12. return -1;
  13. }
  14. printf("nDATA=%d",*buffer);
  15. memset(buffer,0,chunk);
  16. }
  17. return 0;
  18. }
  19.  
  20. int main(int argc, char *argv[]){
  21. int i,chunk=1024;
  22. long size=10000;
  23. printf("Got %ld bytes in chunks of %d...n",size,chunk);
  24. if(eat(size,chunk)==0){
  25. printf("Done, press any key to free the memoryn");
  26. getchar();
  27. }else{
  28. printf("ERROR: Could not allocate the memory");
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement