answer if u can

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2008
Posts: 10
Reputation: xlx16 is an unknown quantity at this point 
Solved Threads: 0
xlx16 xlx16 is offline Offline
Newbie Poster

answer if u can

 
0
  #1
Jul 19th, 2008
/* I need some advice on program bellow,this program is text program
in this program by pressing arrow key you can change your position
in the text and by enter key you can break a line and move the rest of the
line to a new line but this program dosen`t work properly.*/
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<ctype.h>
  4. void pos(char);
  5. void text();
  6. int i, j,k,x=0,y=0,s=0;
  7. char txt[41][79],st[79],ch;
  8. int main()
  9. {
  10. clrscr();
  11. for(j=0;j<41;j++)
  12. for(i=0;i<79;)
  13. txt[j][i]=32;
  14.  
  15. text();
  16. return 0;
  17. }
  18. //******************************************((functions))********************************
  19. void text(){
  20.  
  21. for(j=0;j<41;j++){
  22. for(i=0;i<79;){
  23. ch=getch();
  24. if(isalpha(ch) || isdigit(ch)|| ch==32){
  25. x++;
  26. i++;
  27. txt[j][i]=ch;
  28. putch(ch);
  29. }else
  30. if (ch==13||ch==0){
  31. pos(ch);
  32. }else
  33. if (ch=='=')
  34. goto last;
  35. }//end of for
  36. y++;
  37. }//end of outer for
  38. last:
  39. }
  40. //****************************
  41. void pos(char ch){
  42. if(ch==13){
  43.  
  44. for( int k=i;k<=76;k++,s++)
  45. st[s]=txt[j][k];
  46. y++;
  47. x=0;
  48. printf("\n");
  49. puts(st);
  50. for( int t=j;t<41;t++){
  51. for(int i=0;i<=78;i++){
  52. putch(txt[t][i]);
  53. }
  54. printf("\n");
  55. }
  56. }//end of enter
  57.  
  58. if(ch==0){
  59. ch=getch();
  60.  
  61. if(ch==72){
  62. y=y-1;
  63. gotoxy(x,y);
  64. }
  65. else if(ch==80){
  66. y=y+1;
  67. gotoxy(x, y);
  68. }
  69. else if(ch==75){
  70. x=x-1;
  71. gotoxy(x,y);
  72. }
  73. else if(ch==77){
  74. x=x+1;
  75. gotoxy(x,y);
  76. }
  77. }
  78. }
  79. //***********************************
Last edited by Narue; Jul 19th, 2008 at 10:30 am. Reason: Code tags -- removed email
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: answer if u can

 
0
  #2
Jul 19th, 2008
http://www.catb.org/~esr/faqs/smart-...tml#bespecific

And
http://www.catb.org/~esr/faqs/smart-...html#noprivate

Perhaps you could work on the indentation to being with. It might help you follow the code flow.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: answer if u can

 
0
  #3
Jul 22nd, 2008
What are you forgetting here?
  1. for(j=0;j<41;j++)
  2. for(i=0;i<79;)
  3. txt[j][i]=32;
Hint: it's an infinite loop . . . .

[edit] And it's a lot easier to use character constants like ' ' and '\r' in your code instead of magic numbers like 32 and 13, don't you think? [/edit]
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 251
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: answer if u can

 
0
  #4
Jul 23rd, 2008
Well, I should say that, I don’t even understand on what your are trying to do here. You will have to give some more information. And your code i just such a lot of mess. You are using stuff which you shouldn't be. Few which i pointed out.

1. Using a very old compiler
2. for(i=0;i<79;) --> why are you not incr i ( include i++)
3. goto <-- dont you know that these statement shouldn't be used. Its a bad programming practice.
4. gotoxy is not a standard C function
5. and clrscr getch !
6. Code indentation is horrible. But I thought this time I will do it for you

  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<ctype.h>
  4.  
  5. void pos(char);
  6. void text();
  7.  
  8. int i, j,k,x=0,y=0,s=0;
  9. char txt[41][79],st[79],ch;
  10.  
  11. int main()
  12. {
  13. clrscr();
  14.  
  15. for(j=0;j<41;j++)
  16. for(i=0;i<79;)
  17. txt[j][i]=32;
  18.  
  19. text();
  20. return 0;
  21. }
  22.  
  23. void text()
  24. {
  25. for(j=0;j<41;j++)
  26. {
  27. for(i=0;i<79;)
  28. {
  29. ch=getch();
  30.  
  31. if(isalpha(ch) || isdigit(ch)|| ch==32)
  32. {
  33. x++;
  34. i++;
  35. txt[j][i]=ch;
  36. putch(ch);
  37. }
  38. else
  39. if (ch==13||ch==0)
  40. {
  41. pos(ch);
  42. }
  43. else
  44. if (ch=='=')
  45. goto last;
  46. }//end of for
  47. y++;
  48. }//end of outer for
  49. last:
  50. }
  51.  
  52. void pos(char ch)
  53. {
  54. if(ch==13)
  55. {
  56. for( int k=i;k<=76;k++,s++)
  57. st[s]=txt[j][k];
  58. y++;
  59. x=0;
  60. printf("\n");
  61. puts(st);
  62.  
  63. for( int t=j;t<41;t++)
  64. {
  65. for(int i=0;i<=78;i++)
  66. {
  67. putch(txt[t][i]);
  68. }
  69. printf("\n");
  70. }
  71. }//end of enter
  72.  
  73. if(ch==0)
  74. {
  75. ch=getch();
  76.  
  77. if(ch==72)
  78. {
  79. y=y-1;
  80. gotoxy(x,y);
  81. }
  82. else if(ch==80)
  83. {
  84. y=y+1;
  85. gotoxy(x, y);
  86. }
  87. else if(ch==75)
  88. {
  89. x=x-1;
  90. gotoxy(x,y);
  91. }
  92. else if(ch==77)
  93. {
  94. x=x+1;
  95. gotoxy(x,y);
  96. }
  97. }
  98. }

ssharish
Last edited by ssharish2005; Jul 23rd, 2008 at 11:54 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC