Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. /*********************************
  2. * Name: Liel *
  3. * q5 *
  4. * *
  5. **********************************/
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10.  
  11. #define FALSE 0
  12. #define TRUE 1
  13.  
  14. #define AMOUNT_LETTERS 26
  15.  
  16. void myFgets(char str[][50], int i);
  17. void resetLettersArray(char wor[][50], int lett[], int len);
  18. int pangram(int lett[], int amountLetters);
  19.  
  20. int main (void)
  21. {
  22. char words[10][50]={0};
  23. int letters[AMOUNT_LETTERS]={0};
  24.  
  25. int i=0;
  26.  
  27. printf("Enter up to 10 words, try to make a pangram:\n");
  28.  
  29. do{
  30. myFgets(words, i); //Entered i-time every time until I got to pangram
  31. resetLettersArray(words, letters, 10);
  32.  
  33. if(pangram(letters, AMOUNT_LETTERS)) //If TRUE is returned (1)
  34. {
  35. printf("Its a pangram?\nYes");
  36. }
  37.  
  38. i++;
  39. }while(!(pangram(letters, AMOUNT_LETTERS)) && i<10); //Entered as long as I did not receive 10 strings and also as long as I did not reach a sentence which is pangram
  40.  
  41. if(!(pangram(letters, AMOUNT_LETTERS)))
  42. {
  43. printf("Its a pangram?\nNo");
  44. }
  45. return 0;
  46. }
  47.  
  48. /*
  49. A function that receives a string and remove the enter input after the string
  50. input: Input of string instead of i to absorption of words constituting pangrama
  51. output: void
  52. */
  53. void myFgets(char str[][50], int i)
  54. {
  55.  
  56. fgets(str[i], 50, stdin);
  57. str[i][strcspn(str[i], "\n")]=0;
  58.  
  59. }
  60.  
  61. /*
  62. A function that initializes an array by the letters in the string (a in index 0, b in index 1.)
  63. input: String array, letter array, String array size (10)
  64. output: void
  65. */
  66. void resetLettersArray(char wor[][50], int lett[], int len)
  67. {
  68. int i=0;
  69. int j=0;
  70.  
  71. for(i=0; i<len; i++)
  72. {
  73. for(j=0; j<strlen(wor[i]); j++)//Runs on all characters in the string array
  74. {
  75. lett[wor[i][j]-'a']++;
  76. /*
  77. The same character in the array less 'a' (97) will give the position of the same letter in the letter array
  78. (for example, the letter b- its husky value is 98, 98-97 = 1. ie b instead of 1).
  79. We will add one at this location in the array to know that the same letter was in the string
  80. */
  81. }
  82. }
  83. }
  84.  
  85. /*
  86. Function that checks whether the sentence contains all the letters (Pangram)
  87. input: letter array, letter array size (26 letters)
  88. output: TRUE or FALSE (1 or 0), is the sentence a pangram?
  89. */
  90. int pangram(int lett[], int amountLetters)
  91. {
  92. int i=0;
  93. int check=0;
  94.  
  95. check=TRUE;
  96. for(i=0; i<amountLetters; i++) //Entered 26 times - the size of the letters
  97. {
  98. if(lett[i]<1) //If the set of letters has a number that is less than 1 (that is, not all letters)
  99. {
  100. check=FALSE;
  101. }
  102. }
  103.  
  104. return check;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement