Advertisement
Guest User

Untitled

a guest
May 30th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include<stdio.h>
  2. #define MAXLINE 1000
  3. void reverse(char*);
  4. int getlen(char*,int);
  5. void main()
  6. {
  7. int i=0;
  8. char line[MAXLINE];
  9. printf("nEnter anythingn");
  10. while((getlen(line,MAXLINE))>1)
  11. {
  12. reverse(line);
  13. }
  14. printf("%s",line);//problem here
  15. }
  16. int getlen(char line[],int len)
  17. {
  18. int c,i=0;
  19. while((c=getchar())!=EOF && c!='n' && (i<(len-2)))//last two for n and
  20. {
  21. line[i]=c;
  22. ++i;
  23. }
  24. if(c=='n')
  25. {
  26. line[i]=c;
  27. ++i;
  28. }
  29.  
  30. line[i]='';
  31. return(i);//returns 1 if nothing is written
  32. }
  33. void reverse(char line[])
  34. {
  35. int i=0,j=0;
  36. char temp;
  37. while(line[i]!='')
  38. ++i;
  39. --i;
  40. if(line[i]=='n')
  41. --i;
  42. while(j<i)
  43. {
  44. temp=line[j];
  45. line[j]=line[i];
  46. line[i]=temp;
  47. ++j;
  48. --i;
  49.  
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement