fork download
  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] = "backwards\n";
  9. printf("\nEnter anything\n");
  10. //while((getlen(line,MAXLINE))>1)
  11. // {
  12. printf("%s",line);//problem here
  13. reverse(line);
  14. printf("%s",line);//problem here
  15. //}
  16.  
  17. }
  18. int getlen(char line[],int len)
  19. {
  20. int c,i=0;
  21. while((c=getchar())!=EOF && c!='\n' && (i<(len-2)))//last two for \n and \0
  22. {
  23. line[i]=c;
  24. ++i;
  25. }
  26. if(c=='\n')
  27. {
  28. line[i]=c;
  29. ++i;
  30. }
  31.  
  32. line[i]='\0';
  33. return(i);//returns 1 if nothing is written
  34. }
  35. void reverse(char line[])
  36. {
  37. int i=0,j=0;
  38. char temp;
  39. while(line[i]!='\0')
  40. ++i;
  41. --i;
  42. if(line[i]=='\n')
  43. --i;
  44. while(j<i)
  45. {
  46. temp=line[j];
  47. line[j]=line[i];
  48. line[i]=temp;
  49. ++j;
  50. --i;
  51.  
  52. }
  53.  
  54. }
Runtime error #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
Enter anything
backwards
sdrawkcab