Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // apple xcode
- // paulogp
- /* capicua: numeros e strings */
- #include <stdio.h>
- #include <string.h>
- int capicua (char *the_input);
- int capicua (char *the_input)
- {
- unsigned long i, j;
- if (the_input != NULL) // when using fgets with strtok else strlen(the_input)
- {
- for (i = 0, j = strlen(the_input) - 1; i < j; i++, j--)
- {
- if (the_input[i] != the_input[j])
- return 0;
- }
- }
- else
- {
- return -1; // invalid input (\n)
- }
- return 1;
- }
- int main (int argc, const char * argv[])
- {
- char the_input[20]; // max 20 digits
- char *the_input_ptr;
- int the_result;
- printf("inserir: ");
- fgets(the_input, sizeof(the_input), stdin);
- // removes \n from the end
- // NOTE: the_file_ptr points to the_file_name
- the_input_ptr = strtok (the_input, "\n");
- the_result = capicua (the_input_ptr);
- switch (the_result) {
- case 0:
- puts ("nao e capicua");
- break;
- case 1:
- puts ("capicua");
- break;
- default:
- puts ("invalido");
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement