לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 31-10-2007, 00:27
צלמית המשתמש של HEN_K
  HEN_K HEN_K אינו מחובר  
 
חבר מתאריך: 10.05.06
הודעות: 583
בעיה בפונקציה ()CLOCK ב-C

שלום אני בונה תכנית שבה המשתמש מצייר משהו עם העכבר ואחרי זה המחשב מצייר את אותו ציור באותו קצב.
נכון לעכשיו התכנית לא גמורה,הגעתי רק לחלק שבו אני כותב את הנתונים לקובץ (קואורדינטות של כל פיקסל וכמה זמן לקח עד שהמשתמש צייר אותו), בעצם התכנית עדיין לא אמורה לעשות כלום חוץ מלקלוט את הציור (את נתוניו) ולכתוב את הנתונים (של כל פיקסל) לקובץ.
בשביל לבדוק כמה זמן לקח עד שצוייר הפיקסל השתמשתי בפונקצייה CLOCK().
הבעיה שלי היא שמשום מה תמיד מתקבל לי שעברו 0 שניות.
מה הבעיה?
הנה הקוד (לא כל השורות ישרות משום מה,אבל באדיטור שלי זה בסדר...) :

קוד:
#include <graphics.h> #include <dos.h> #include <stdio.h> #include <conio.h> #include <time.h> void showMouse(union REGS i, union REGS o) { i.x.ax=1; int86(0x33,&i,&o); } void checkMouse(union REGS i, union REGS o) { i.x.ax=0; int86(0x33,&i,&o); } void buttonPressed(union REGS i, union REGS o, int *button, int *x, int *y) { i.x.ax=3; int86(0x33,&i,&o); *button=o.x.bx&7; *x=o.x.cx; *y=o.x.dx; } void hideMouse(union REGS i, union REGS o) { i.x.ax=2; int86(0x33,&i,&o); } main() { int gd=DETECT,gm; union REGS i,o; int button=0, x1, y1, x2, y2; clock_t time_start, time_end; FILE *f; initgraph(&gd,&gm,""); //switch to graphic mode checkMouse(i,o); //check if mouse is available while(!kbhit()) { showMouse(i,o); //show the mouse time_start=clock(); //start stoper buttonPressed(i,o,&button,&x1,&y1); //check what button was pressed and the co-ordinates of the mouse x2=x1; y2=y1; time_end=clock(); //end stoper while(button==1) //left button was pressed { /*** write the information to file ***/ f=fopen("DRAWING.txt","a"); fprintf(f, "%d %d %d %d %.1f\n", x1,y1, x2,y2,(time_end-time_start)/CLK_TCK ); fclose(f); hideMouse(i,o); //hide the mouse line(x1,y1,x2,y2); time_start=clock(); x1=x2; y1=y2; buttonPressed(i,o,&button,&x2,&y2); if(button==1) time_end=clock(); /*** write the information to file ***/ f=fopen("Drawing","a"); fprintf(f, "%d %d %d %d %.1f\n", x1,y1, x2,y2,(time_end-time_start)/CLK_TCK ); fclose(f); } } getch(); restorecrtmode(); }


תודה גדולה לעוזרים....
_____________________________________
אדם חכם לומד מהטעויות שלו,


אדם ממש חכם לומד גם מטעויות של אחרים.


נערך לאחרונה ע"י HEN_K בתאריך 31-10-2007 בשעה 00:29.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #3  
ישן 31-10-2007, 02:10
צלמית המשתמש של HEN_K
  HEN_K HEN_K אינו מחובר  
 
חבר מתאריך: 10.05.06
הודעות: 583
המממ...עדכון...
בתגובה להודעה מספר 1 שנכתבה על ידי HEN_K שמתחילה ב "בעיה בפונקציה ()CLOCK ב-C"

טוב מצאתי בעיה אחת....אז עכשיו אם מדובר בכמה שניות או אפילו חצי שניה אז הכל בסדר....אבל אם מדובר בזמן קצר יותר זה לא עובד.... אם מציירים קו ברצף אז הזמן של כל פיקסל ממש ממש קטן וכשאני כותב את המספר הקטן הזה לקובץ זה כותב רק 6 ספרות אחרי הנקודה וכנראה זה לא מספיק.....כנראה המספר יותר קטן.....ולכן מה שיוצא זה 0.000000......או שזאת לא הבעיה?
הנה הקוד המעודכן:
קוד:
#include <graphics.h> #include <dos.h> #include <stdio.h> #include <conio.h> #include <time.h> #include <string.h> void showMouse(union REGS i, union REGS o) { i.x.ax=1; int86(0x33,&i,&o); } void checkMouse(union REGS i, union REGS o) { i.x.ax=0; int86(0x33,&i,&o); } void buttonPressed(union REGS i, union REGS o, int *button, int *x, int *y) { i.x.ax=3; int86(0x33,&i,&o); *button=o.x.bx&7; *x=o.x.cx; *y=o.x.dx; } void hideMouse(union REGS i, union REGS o) { i.x.ax=2; int86(0x33,&i,&o); } main() { int gd=DETECT,gm; union REGS i,o; int button=0, x1, y1, x2, y2; clock_t time_start, time_end; FILE *f; long double stoper=0.0; initgraph(&gd,&gm,""); //switch to graphic mode checkMouse(i,o); //check if mouse is available while(!kbhit()) { showMouse(i,o); //show the mouse time_start=clock(); //start stoper buttonPressed(i,o,&button,&x1,&y1); //check what button was pressed and the co-ordinates of the mouse x2=x1; y2=y1; time_end=clock(); //end stoper stoper=stoper+( (time_end-time_start) / CLK_TCK ); while(button==1) //left button was pressed { /*** write the information to file ***/ f=fopen("DRAWING.txt","a"); fprintf(f, "%d %d %d %d %f\n", x1,y1,x2,y2,stoper); fclose(f); hideMouse(i,o); //hide the mouse line(x1,y1,x2,y2); stoper=0.0; time_start=clock(); x1=x2; y1=y2; buttonPressed(i,o,&button,&x2,&y2); time_end=clock(); stoper=(time_end-time_start) / CLK_TCK; } } getch(); restorecrtmode(); }


הצעות?
_____________________________________
אדם חכם לומד מהטעויות שלו,


אדם ממש חכם לומד גם מטעויות של אחרים.


נערך לאחרונה ע"י HEN_K בתאריך 31-10-2007 בשעה 02:36.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #13  
ישן 08-11-2007, 00:21
צלמית המשתמש של maind
  maind maind אינו מחובר  
 
חבר מתאריך: 08.10.02
הודעות: 827
בתגובה להודעה מספר 12 שנכתבה על ידי HEN_K שמתחילה ב "אף אחד לא יודע מה לעשות??"

אתה יכול למדוד זמנים הקטנים ממילישניות בעזרת
QueryPerformanceCounter ב API, לדוגמא:

קוד:
LARGE_INTEGER ticksPerSecond; LARGE_INTEGER starttime; LARGE_INTEGER endtime; double seconds_passed; //Get ticks rate QueryPerformanceFrequency(&ticksPerSecond); //Get start time QueryPerformanceCounter(&starttime); //Do something.... Sleep(200); //Get end time QueryPerformanceCounter(&endtime); //Calculate seconds seconds_passed = (double) (endtime.QuadPart - starttime.QuadPart) / (double) ticksPerSecond.QuadPart; printf("%.9f seconds has passed\n", seconds_passed);


או להכניס את זה לתוך סט של פוקנציות,
קוד:
typedef struct prof_timer_t { LARGE_INTEGER time_start; LARGE_INTEGER time_stop; } prof_timer_t; void prof_timer_start(prof_timer_t *timer) { QueryPerformanceCounter(&timer->time_start); } void prof_timer_stop(prof_timer_t *timer) { QueryPerformanceCounter(&timer->time_stop); } double prof_timer_get_duration_in_secs(prof_timer_t *timer) { LARGE_INTEGER freq; double duration; QueryPerformanceFrequency(&freq); duration = (double)(timer->time_stop.QuadPart-timer->time_start.QuadPart)/(double)freq.QuadPart; return duration; }


ואז להשתמש בנוחות ככה:

קוד:
prof_timer_t test; prof_timer_start(&test); //Do something.... Sleep(200); //Stop prof_timer_stop(&test); //Result printf("%.9f seconds has passed\n", prof_timer_get_duration_in_secs(&test));
_____________________________________
Error: Keyboard not found
Press F1 to continue


נערך לאחרונה ע"י maind בתאריך 08-11-2007 בשעה 00:30.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 11:20

הדף נוצר ב 0.05 שניות עם 12 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2026 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר