Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #define atoa(x,y) #x
  3. int main() {
  4. FILE * fp;
  5. char c;
  6.  
  7. fp = fopen("1.txt", "r");
  8. int ck=0;
  9. int flag=1;
  10.  
  11. char name[100],age[100],nation[100],work[100];
  12. int agee=0;
  13.  
  14. int i=0;
  15.  
  16. while ((c = getc(fp)) != EOF) {
  17.  
  18. if(ck==11 && flag==1)
  19. {
  20. if(c=='.')
  21. {
  22. flag++;
  23. ck=0;
  24. name[i]='\0';
  25. i=0;
  26. }
  27. else
  28. {
  29. name[i] = c;
  30. i++;
  31. }
  32. }
  33. else if(ck==16 && flag==2)
  34. {
  35. if(c=='.')
  36. {
  37. flag++;
  38. ck=0;
  39. age[i]='\0';
  40. i=0;
  41. }
  42. else
  43. {
  44. age[i] = c;
  45. i++;
  46. }
  47. }
  48. else if(ck==20 && flag==3)
  49. {
  50. if(c=='.')
  51. {
  52. flag++;
  53. ck=0;
  54. nation[i]='\0';
  55. i=0;
  56. }
  57. else
  58. {
  59. nation[i] = c;
  60. i++;
  61. }
  62. }
  63. else if(ck==29 && flag==4)
  64. {
  65. if(c=='.')
  66. {
  67. flag++;
  68. ck=0;
  69. work[i]='\0';
  70. i=0;
  71. }
  72. else
  73. {
  74. work[i] = c;
  75. i++;
  76. }
  77. }
  78.  
  79. else ck++;
  80. }
  81. fclose(fp);
  82.  
  83. while(age[i])
  84. {
  85. agee = agee*10 + age[i]-'0';
  86. i++;
  87. }
  88. agee = 2019-agee;
  89. printf("%s\n%d\n%s\n%s\n",name,agee,nation,work);
  90.  
  91.  
  92. printf("\n");
  93. ck=0;
  94. int j=0;
  95.  
  96. char mail[100];
  97.  
  98. printf("Name: ");
  99. for(i=0;i<strlen(name);i++)
  100. {
  101. if(name[i]==' ')
  102. {
  103. ck=1;
  104. }
  105. else if(ck==1)
  106. {
  107. printf("%c",name[i]);
  108. mail[j] = name[i];
  109. j++;
  110. }
  111. }
  112. printf("\nAge: %d\n",agee);
  113. printf("Nationality: %s\n",nation);
  114.  
  115. char str_age[100];
  116.  
  117. sprintf(str_age, "%d", agee);
  118.  
  119. for(i=0;str_age[i]!='\0';i++)
  120. {
  121. mail[j] = str_age[i];
  122. j++;
  123. }
  124. mail[j]=mail[0];
  125. j++;
  126. mail[j]='@';
  127. j++;
  128. mail[j]='g';
  129. j++;
  130. mail[j]='m';
  131. j++;
  132. mail[j]='a';
  133. j++;
  134. mail[j]='i';
  135. j++;
  136. mail[j]='l';
  137. j++;
  138. mail[j]='.';
  139. j++;
  140. mail[j]='c';
  141. j++;
  142. mail[j]='o';
  143. j++;
  144. mail[j]='m';
  145. j++;
  146. mail[j]='\0';
  147.  
  148. printf("%s\n",mail);
  149.  
  150. return 0;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement