Guest User

Untitled

a guest
Nov 19th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. //Programmer Dr. Aung Win Htut
  2. //Sample program for Senior Inventor Class
  3. #include<stdio.h>
  4. #include<conio.h>
  5. #include<stdlib.h>
  6. #include<string.h>
  7.  
  8. #define RECORD_LENGTH 60
  9. int funArraySize(char *arr);
  10. struct BUFFER splitTwoArray(char* arr, char ch);
  11. struct DATA splitData(char* arr, char ch);
  12. void copyArray(char *from, char* to);
  13.  
  14. struct DATA {
  15. char name[60];
  16. char age[60];
  17. char email[60];
  18. char ph[60];
  19. };
  20.  
  21. struct BUFFER{
  22. char first[60];
  23. char second[60];
  24. };
  25.  
  26. int main()
  27. {
  28. struct DATA people[20];
  29. int i=0;
  30. FILE* fptr;
  31. char stock_price_shares[RECORD_LENGTH+1];
  32.  
  33. fptr = fopen("e:\\cpp\\PORTFOLIO.DAT","r");
  34.  
  35. if( fptr == NULL)
  36. {
  37. printf("\nCannot read file ");
  38. exit(1);
  39. }
  40. else{
  41. printf("\n%d - 12345\n ",funArraySize("12345"));
  42. while(fgets(stock_price_shares,RECORD_LENGTH+1,fptr)!=NULL)
  43. {
  44. printf("%d - ",funArraySize(stock_price_shares));
  45. printf("%s",stock_price_shares);
  46. people[i]=splitData(stock_price_shares,'#');
  47. i++;
  48. }
  49. fclose(fptr);
  50. }
  51.  
  52. for(int j=0;j<i;j++)
  53. {
  54. printf("name of roll %d is %s \n",j+1,people[j].name );
  55. printf("age of roll %d is %s \n",j+1,people[j].age );
  56. printf("emial of roll %d is %s \n",j+1,people[j].email );
  57. printf("phone of roll %d is %s \n\n",j+1,people[j].ph );
  58. }
  59.  
  60. getch();
  61. return 0;
  62.  
  63. }
  64.  
  65. struct DATA splitData(char* arr, char ch)
  66. {
  67. struct DATA result;
  68. struct BUFFER buf;
  69. buf=splitTwoArray(arr,ch);
  70. //strcpy(result.name,buf.first);
  71. copyArray(buf.first, result.name);
  72. buf=splitTwoArray(buf.second ,ch);
  73. strcpy(result.age,buf.first );
  74. buf=splitTwoArray(buf.second ,ch);
  75. strcpy(result.email ,buf.first );
  76. strcpy(result.ph ,buf.second );
  77. return result;
  78. }
  79.  
  80. struct BUFFER splitTwoArray(char* arr, char ch)
  81. {
  82. struct BUFFER buffer;
  83. int size=0;
  84. int i=0;
  85. int location_of_sh=0;
  86. size = funArraySize(arr);
  87. for(i=0;i<size;i++)
  88. {
  89. if(arr[i]==ch)
  90. {
  91. location_of_sh=i;
  92. break;
  93. }
  94. }
  95.  
  96. for(i=0;i<location_of_sh;i++)
  97. {
  98. buffer.first[i] =arr[i];
  99. }
  100. buffer.first[i]=0;
  101. for(i=location_of_sh+1;i<size;i++)
  102. {
  103. buffer.second[i-location_of_sh-1] =arr[i];
  104. }
  105. buffer.second[i-location_of_sh-1] =NULL;
  106.  
  107. return buffer;
  108. }
  109.  
  110.  
  111.  
  112.  
  113. int funArraySize(char *arr)
  114. {
  115. int count=0;
  116. while(arr[count]!=NULL) //NULL=0
  117. {
  118. count++;
  119. }
  120. return count-1;
  121. }
  122.  
  123.  
  124.  
  125.  
  126.  
  127. int funArraySize(int *arr)
  128. {
  129. return 0;
  130. }
  131.  
  132. void copyArray(char *from, char* to)
  133. {
  134. while(*from!=0)
  135. {
  136. *to++=*from++;
  137. }
  138. *to++=NULL;
  139. }
Add Comment
Please, Sign In to add comment