Guest User

Untitled

a guest
Feb 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define MAX_CHARS 1000
  4.  
  5. void encode(char *s1, char *s2);
  6. int read_line(char *str, int n);
  7.  
  8. int main(void)
  9. {
  10.  
  11. int word_chars;
  12. char wrds[MAX_CHARS+1];
  13. char wrds2[MAX_CHARS+1];
  14.  
  15. printf("Enter a word: ");
  16. word_chars = read_line(wrds, MAX_CHARS);
  17.  
  18. encode(wrds,wrds2) //And i know in my mind how to call it but don't know to
  19. // write it
  20.  
  21. printf("Output: %s", wrds2);
  22.  
  23. return 0;
  24. }
  25.  
  26. void encode(char *s1, char *s2) //this is the function i need help with
  27. { //please!
  28. char *func_ptr1 =s1; char *func_ptr2=s2; //This is how far I have got to.
  29. char *temp_ptr=s1; //I am getting frustrated and have
  30. //no clue what to do.
  31.  
  32. for(func_ptr1=s2; *s1 != ''; func_ptr1++)
  33. {
  34. strcpy(s2++, s1++);
  35. }
  36.  
  37. }
  38.  
  39. int read_line(char *str, int n) //This function eliminates the white spaces
  40. { //and gets the characters
  41. int words; int store=0;
  42.  
  43. while((words=getchar())!='n')
  44. {
  45. if(store<n)
  46. {
  47. *str++=words;
  48. store++;
  49. }
  50. }
  51. while((words=getchar()) == ' ');
  52.  
  53. *str++=words;
  54.  
  55. store++;
  56.  
  57. *str ='';
  58.  
  59. return store;
  60. }
Add Comment
Please, Sign In to add comment