Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define MAX 101
- void word();
- void check(char word[]);
- int main()
- {
- word();
- return 0;
- }
- /*
- This function scans
- a word from the user
- and removes the spaces.
- */
- void word()
- {
- char word[MAX] = {0}; //setting strings
- int length = 0; //setting variables
- int i = 0;
- int j = 0;
- int iBackup = 0;
- printf("Please enter a word (100 characters max): "); //Getting a word and it's length
- fgets(word, MAX, stdin);
- length = strlen(word);
- word[length - 1] = 0;
- while(i < MAX) //checking every single place for a space
- {
- if(word[i] == ' ')
- {
- iBackup = i;
- word[i] = 0; //changing space to NULL
- while(i < length) //moving NULL to the last place
- {
- j = i + 1;
- word[i] = word[j];
- i++;
- }
- i = iBackup;
- length -= 1 ;
- }
- i++;
- }
- check(word);
- }
- /*
- This function gets the word without spaces
- and checks if they are palandromes
- */
- void check(char word[])
- {
- int i = 1; //setting variables
- int length = 0;
- int count = 0;
- length = strlen(word);
- while(i <= length/2)
- {
- if(word[i-1] == word[length - i]) //checking for palandromes
- {
- count++;
- }
- i++;
- }
- if(count == length/2)
- {
- printf("Yes\n");
- }
- else
- {
- printf("No\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement