Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4.  
  5. /*int palindrome(FILE &pfp, char *input)
  6. {
  7.  
  8. return 0;
  9. }
  10.  
  11. int cipher(FILE &cfp, char *input)
  12. {
  13.  
  14. return 0;
  15. }
  16. */
  17. int main (void)
  18. {
  19. FILE* ifp = fopen("input.txt", "r");
  20. FILE* pfp = fopen("palindromes.txt", "w");
  21. FILE* cfp = fopen("cipher.txt", "w");
  22.  
  23. char input[32] = {0};
  24. char inputCopy[32] = {0};
  25. (fscanf(ifp, "%s", input));
  26. printf(input);
  27. printf("\n");
  28. while (fscanf(ifp, "%s", (input)) != EOF) {
  29. printf("work \n");
  30. //palindrome section start
  31. printf(input);
  32. unsigned int palindromeLength = (unsigned int) (strlen( input )/2);
  33. char front[palindromeLength + 1];
  34. char back[palindromeLength + 1];
  35. memcpy( front, input, palindromeLength);
  36. strcpy(inputCopy, input);
  37. strrev(inputCopy);
  38. memcpy( back, inputCopy, palindromeLength);
  39. if (strcmp(front, back) == 1){
  40. fprintf(pfp, "%s", input);
  41. };
  42. //cipher section start
  43. strcpy(inputCopy, input);
  44. for (int i = 0; i < (char) (strlen(inputCopy)); i++){
  45. inputCopy[i] = (char) (inputCopy[i] + 13);
  46. if (inputCopy[i] > 'z') {
  47. inputCopy[i] = (char) (inputCopy[i] - 26);
  48. }
  49. }
  50. fprintf(cfp, "%s", inputCopy);
  51. }
  52. fclose(ifp);
  53. fclose(pfp);
  54. fclose(cfp);
  55. printf("done \n");
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement