| | |
answer if u can
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2008
Posts: 10
Reputation:
Solved Threads: 0
/* 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.*/
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.*/
C Syntax (Toggle Plain Text)
#include<stdio.h> #include<conio.h> #include<ctype.h> void pos(char); void text(); int i, j,k,x=0,y=0,s=0; char txt[41][79],st[79],ch; int main() { clrscr(); for(j=0;j<41;j++) for(i=0;i<79;) txt[j][i]=32; text(); return 0; } //******************************************((functions))******************************** void text(){ for(j=0;j<41;j++){ for(i=0;i<79;){ ch=getch(); if(isalpha(ch) || isdigit(ch)|| ch==32){ x++; i++; txt[j][i]=ch; putch(ch); }else if (ch==13||ch==0){ pos(ch); }else if (ch=='=') goto last; }//end of for y++; }//end of outer for last: } //**************************** void pos(char ch){ if(ch==13){ for( int k=i;k<=76;k++,s++) st[s]=txt[j][k]; y++; x=0; printf("\n"); puts(st); for( int t=j;t<41;t++){ for(int i=0;i<=78;i++){ putch(txt[t][i]); } printf("\n"); } }//end of enter if(ch==0){ ch=getch(); if(ch==72){ y=y-1; gotoxy(x,y); } else if(ch==80){ y=y+1; gotoxy(x, y); } else if(ch==75){ x=x-1; gotoxy(x,y); } else if(ch==77){ x=x+1; gotoxy(x,y); } } } //***********************************
Last edited by Narue; Jul 19th, 2008 at 10:30 am. Reason: Code tags -- removed email
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.
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.
What are you forgetting here?
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]
C Syntax (Toggle Plain Text)
for(j=0;j<41;j++) for(i=0;i<79;) txt[j][i]=32;
[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
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
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.
3.
4.
5. and
6. Code indentation is horrible. But I thought this time I will do it for you
ssharish
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 function5. and
clrscr getch !6. Code indentation is horrible. But I thought this time I will do it for you
”C” Syntax (Toggle Plain Text)
#include<stdio.h> #include<conio.h> #include<ctype.h> void pos(char); void text(); int i, j,k,x=0,y=0,s=0; char txt[41][79],st[79],ch; int main() { clrscr(); for(j=0;j<41;j++) for(i=0;i<79;) txt[j][i]=32; text(); return 0; } void text() { for(j=0;j<41;j++) { for(i=0;i<79;) { ch=getch(); if(isalpha(ch) || isdigit(ch)|| ch==32) { x++; i++; txt[j][i]=ch; putch(ch); } else if (ch==13||ch==0) { pos(ch); } else if (ch=='=') goto last; }//end of for y++; }//end of outer for last: } void pos(char ch) { if(ch==13) { for( int k=i;k<=76;k++,s++) st[s]=txt[j][k]; y++; x=0; printf("\n"); puts(st); for( int t=j;t<41;t++) { for(int i=0;i<=78;i++) { putch(txt[t][i]); } printf("\n"); } }//end of enter if(ch==0) { ch=getch(); if(ch==72) { y=y-1; gotoxy(x,y); } else if(ch==80) { y=y+1; gotoxy(x, y); } else if(ch==75) { x=x-1; gotoxy(x,y); } else if(ch==77) { x=x+1; gotoxy(x,y); } } }
ssharish
Last edited by ssharish2005; Jul 23rd, 2008 at 11:54 pm.
![]() |
Similar Threads
- The "answer movie name with movie name" game (Posting Games)
- Cubic equation (C++)
- I have another homework question that i'm not sure what the answer is. (C)
- U$ 100.000.00 For Who Answer This Simple Question: (Java)
- This has to be a simple question to answer. (Visual Basic 4 / 5 / 6)
- please answer this question havnt ne others (C#)
- ATI's answer to Nvidia's SLI (Monitors, Displays and Video Cards)
- A question on java script?(Please answer ASAP) (Java)
- Cannot incorporate equals method for a yes or no answer. (Java)
Other Threads in the C Forum
- Previous Thread: Want to receive data thru serial port
- Next Thread: Sorting strings - segmentation fault
| Thread Tools | Search this Thread |
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory dynamic fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest kernel km linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power probleminc program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming stack standard string strings structures systemcall testautomation turboc unix user variable voidmain() wab win32api windows.h






