Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************
- * Name: Liel *
- * q5 *
- * *
- **********************************/
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #define FALSE 0
- #define TRUE 1
- #define AMOUNT_LETTERS 26
- void myFgets(char str[][50], int i);
- void resetLettersArray(char wor[][50], int lett[], int len);
- int pangram(int lett[], int amountLetters);
- int main (void)
- {
- char words[10][50]={0};
- int letters[AMOUNT_LETTERS]={0};
- int i=0;
- printf("Enter up to 10 words, try to make a pangram:\n");
- do{
- myFgets(words, i); //Entered i-time every time until I got to pangram
- resetLettersArray(words, letters, 10);
- if(pangram(letters, AMOUNT_LETTERS)) //If TRUE is returned (1)
- {
- printf("Its a pangram?\nYes");
- }
- i++;
- }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
- if(!(pangram(letters, AMOUNT_LETTERS)))
- {
- printf("Its a pangram?\nNo");
- }
- return 0;
- }
- /*
- A function that receives a string and remove the enter input after the string
- input: Input of string instead of i to absorption of words constituting pangrama
- output: void
- */
- void myFgets(char str[][50], int i)
- {
- fgets(str[i], 50, stdin);
- str[i][strcspn(str[i], "\n")]=0;
- }
- /*
- A function that initializes an array by the letters in the string (a in index 0, b in index 1.)
- input: String array, letter array, String array size (10)
- output: void
- */
- void resetLettersArray(char wor[][50], int lett[], int len)
- {
- int i=0;
- int j=0;
- for(i=0; i<len; i++)
- {
- for(j=0; j<strlen(wor[i]); j++)//Runs on all characters in the string array
- {
- lett[wor[i][j]-'a']++;
- /*
- The same character in the array less 'a' (97) will give the position of the same letter in the letter array
- (for example, the letter b- its husky value is 98, 98-97 = 1. ie b instead of 1).
- We will add one at this location in the array to know that the same letter was in the string
- */
- }
- }
- }
- /*
- Function that checks whether the sentence contains all the letters (Pangram)
- input: letter array, letter array size (26 letters)
- output: TRUE or FALSE (1 or 0), is the sentence a pangram?
- */
- int pangram(int lett[], int amountLetters)
- {
- int i=0;
- int check=0;
- check=TRUE;
- for(i=0; i<amountLetters; i++) //Entered 26 times - the size of the letters
- {
- if(lett[i]<1) //If the set of letters has a number that is less than 1 (that is, not all letters)
- {
- check=FALSE;
- }
- }
- return check;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement