1. #include <unistd.h> /* Symbolic Constants */
  2. #include <sys/types.h> /* Primitive System Data Types */
  3. #include <errno.h> /* Errors */
  4. #include <stdio.h> /* Input/Output */
  5. #include <stdlib.h> /* General Utilities */
  6. #include <string.h> /* String handling */
  7. #include <limits.h>
  8. #define NUM_THREADS 10
  9.  
  10. int BUFF_SIZE = 10;
  11. char *buffer[10];
  12.  
  13.  
  14.  
  15. struct thread_data{
  16. int thread_id;
  17. int start_index;
  18. int end_index;
  19. double average;
  20. };
  21.  
  22. struct thread_data thread_data_array[NUM_THREADS];
  23.  
  24. void load_sharedbuffer(int c, char *file_name){
  25. FILE *file;
  26.  
  27. if((file = fopen(file_name, "r"))==NULL)
  28. {
  29. printf("can't open %s\n", "testinput"); exit(1);
  30. } else {
  31.  
  32. int i = 0;
  33. if (buffer == NULL) perror ("Memory Error");
  34. for(i=0; i<BUFF_SIZE; i++)
  35. {
  36. buffer[i] = (char*) calloc(sizeof(char*),80);
  37. fgets(buffer[i],79, file);
  38. }
  39. }
  40. fclose(file);
  41. /*terminate*/
  42.  
  43. }
  44.  
  45.  
  46. int main(int argc, char **argv) {
  47.  
  48. if(argc<2) {load_sharedbuffer(argc,"testinput");}
  49. else load_sharedbuffer(argc, argv[1]);
  50.  
  51.  
  52. int j = 0;
  53. for(j=0; j<BUFF_SIZE; j++) printf("%s",buffer[j]);
  54.  
  55. return 0;
  56. }
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.