dmesticg

main.c

Nov 30th, 2020 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. #include "headers.h"
  2.  
  3.  
  4. int main(void) {
  5. struct sentence *firstSentence = NULL;
  6. struct sentence *currSentence = NULL;
  7. struct sentence *prevSentence = NULL;
  8. int keepGathering = 1;
  9. int sentenceCount = 1;
  10.  
  11. for (int i = 0; i < keepGathering; i++) {
  12. char *read = calloc(1000, sizeof(char));
  13. read = gatherInput("Enter some text or enter nothing to get print and begin search");
  14. fflush(stdin);
  15.  
  16. if (read[0] == NULL) {
  17. keepGathering = 0;
  18. }
  19.  
  20. else {
  21. keepGathering++;
  22. currSentence = processInput(read,sentenceCount);
  23.  
  24. if (sentenceCount == 1) {
  25. firstSentence = currSentence;
  26. }
  27.  
  28. if (prevSentence != NULL) {
  29. prevSentence->nextSent = currSentence;
  30. }
  31.  
  32. prevSentence = currSentence;
  33. sentenceCount++;
  34. }
  35. }
  36. printOut(firstSentence);
  37.  
  38.  
  39. int keepSearching = 1;
  40. char *searchTerm = NULL;
  41. searchTerm = calloc(1000, sizeof(char));
  42. for (int i = 0; i < keepSearching; i++) {
  43. searchTerm = gatherInput("Enter a search term\n");
  44. fflush(stdin);
  45.  
  46. if (searchTerm[0] == NULL) {
  47. keepSearching = 0;
  48. }
  49. else {
  50. keepSearching++;
  51. searchFunction(firstSentence, searchTerm);
  52. }
  53.  
  54. }
  55. printf("finished searching, Switching to line removal\n");
  56. fflush(stdout);
  57.  
  58. // int *lineNumber = NULL;
  59. // lineNumber = gatherNum("Please enter line number to remove\n");
  60. // removeLine(lineNumber, firstSentence, sentenceCount);
  61.  
  62. int keepRemoving = 1;
  63. int *lineNumber = NULL;
  64. lineNumber = calloc(1000, sizeof(int));
  65.  
  66. for (int i = 0; i < keepRemoving; i++) {
  67. if (sentenceCount == 0) {
  68. printf("all text removed, program closing\n");
  69. fflush(stdout);
  70. break;
  71. }
  72.  
  73. lineNumber = gatherNum("Enter line number to remove\n");
  74. fflush(stdin);
  75. if (*lineNumber == 0 || *lineNumber == NULL) {
  76. printf("removal finished\n");
  77. fflush(stdout);
  78. break;
  79. }
  80. if (sentenceCount == 0) {
  81. printf("finished removing, Ending Program\n");
  82. fflush(stdout);
  83. break;
  84. }
  85. if (*lineNumber != NULL && sentenceCount > 0) {
  86. keepRemoving++;
  87. if (sentenceCount == 0) {
  88. printf("finished removing, Ending Program\n");
  89. fflush(stdout);
  90. break;
  91. }
  92. if (*lineNumber == 1) {
  93. if (sentenceCount != 1){
  94. firstSentence = firstSentence->nextSent;
  95. sentenceCount--;
  96. removeLine(lineNumber, firstSentence, sentenceCount);
  97. } else {
  98. break;
  99. }
  100. }
  101. else {
  102. removeLine(lineNumber, firstSentence, sentenceCount);
  103. sentenceCount--;
  104. }
  105. }
  106.  
  107. }
  108. printf("finished removing, Ending Program\n");
  109. fflush(stdout);
  110.  
  111. return 0;
  112. }
  113.  
Add Comment
Please, Sign In to add comment