Guest User

Untitled

a guest
Nov 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. /*
  2.  
  3. Description: Write a function that finds and returns through an output parameter the longest common suffix of two words.
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10.  
  11. #define SIZE 15
  12.  
  13. //NO PARAMETERS
  14. //NO RETURNS
  15. //TELLS USER WHAT THE PROGRAM DOES AND HOW TO USE IT PROPERLY
  16. void userPrompt(void)
  17. {
  18. printf("You will be prompted to input two words. This program will read both words and output the longest common suffix\n");
  19. printf("Example: enter words GLOVE and DOVE\n");
  20. printf("Output: Longest common suffix: OVE\n\n");
  21. }
  22.  
  23. //TAKES IN THE TWO USER INPUTS AND PASSES A NEW VALUE SUFFIX
  24. //NO RETURNS
  25. //TAKES BOTH INPUTED WORDS FINDS THE COMMON SUFFIX AND PASSES IT BACK TO MAIN
  26. void calculateSuffix(char* Input1, char* Input2, char* suffix)
  27. {
  28. char word1[SIZE], word2[SIZE];
  29. int i = 0;
  30.  
  31. strcpy(word1, Input1);
  32. strcpy(word2, Input2);
  33.  
  34. i = 0;
  35.  
  36. while(strcmp(word1, word2) != 0)
  37. {
  38. i++;
  39. printf("\n%d", i);
  40. }
  41. printf("%d", i);
  42. /*
  43. strncpy(suffix, word1, i);
  44. suffix[i] = '\0';
  45. */
  46.  
  47. }
  48. //PASSES TWO USER INPUTS TO MAIN
  49. //NO RETURNS
  50. //PROMPTS USER TO INPUT TWO WORDS AND PASS THEM
  51. void userInput(char *Input1, char *Input2, char *suffix)
  52. {
  53. printf("Enter first word: ");
  54. fscanf(stdin, "%s", Input1);
  55. printf("\n%s", Input1);
  56.  
  57.  
  58. printf("Enter second word: ");
  59. fscanf(stdin, "%s", Input2);
  60. printf("\n%s", Input2);
  61.  
  62. calculateSuffix(Input1, Input2, suffix);
  63.  
  64. }
  65. //NO PARAMETERS
  66. //NO RETURNS
  67. //CALLS FUNCTIONS AND PRINTS COMMON SUFFIX
  68. int main()
  69. {
  70. char Input1[SIZE], Input2[SIZE], suffix[SIZE];
  71.  
  72. userPrompt();
  73. userInput(Input1, Input2, suffix);
  74. //printf("%s %s",Input1, Input2);
  75.  
  76. // calculateSuffix(Input1, Input2, &suffix);
  77. //printf("%s", suffix);
  78.  
  79. printf("\n");
  80. //system("pause");
  81. return 0;
  82. }
Add Comment
Please, Sign In to add comment