Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. /*********************************
  2. * Name: Liel *
  3. * q1 *
  4. * *
  5. **********************************/
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10.  
  11. #define TRUE 1
  12. #define FALSE 0
  13.  
  14. void myFgets(char str[], int len);
  15. void encoded(char str[], int newStr[]);
  16.  
  17. int main (void)
  18. {
  19. char str[50]={0};
  20. char stopStr[]="stop+0000";
  21.  
  22. int newStr[50]={0};
  23.  
  24. int check=0;
  25.  
  26. check=TRUE;
  27. do{
  28. printf("pleas enter a string: ");
  29. myFgets(str, 50);
  30.  
  31. if(strcmp(str, stopStr)==0)
  32. {
  33. check=FALSE;
  34. printf("Thank you");
  35. }
  36. else
  37. {
  38. encoded(str, newStr);
  39. }
  40.  
  41.  
  42. }while(check);
  43.  
  44. return 0;
  45. }
  46.  
  47. void myFgets(char str[], int len)
  48. {
  49. fgets(str, len, stdin);
  50. str[strcspn(str, "\n")]=0;
  51. }
  52.  
  53. void encoded(char str[], int newStr[])
  54. {
  55. int plusIndex=0;
  56.  
  57. int i=0;
  58.  
  59. plusIndex=strcspn(str, "+");
  60.  
  61. for(i=0; i<plusIndex; i++)
  62. {
  63. newStr[i]=str[i]+(str[plusIndex+i+1]-'0');
  64. if(newStr[i]>'z')
  65. {
  66. printf("%c ",('a'-1)+(str[plusIndex+i+1]-'0') );
  67. }
  68. else
  69. {
  70. printf("%c ",newStr[i]);
  71. }
  72. }
  73. printf("\n");
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement