Hi, With reference to Mr Richards reply i made some changes which will make ur program to work. The changes are commented. the slot size should be created dynamically as suggested. Hope u can understand the code. I am beginner too. Good luck //OBJECT: To make a program to take the input from user as the names of the owner, chassis numbers, //model, car brand and to store them in structures #include<stdio.h> #include<conio.h> #include<string.h> struct data{ char oname[20]; int chno; int model; char brand[20]; }; const int slot =2; //changed here as pointed out by Mr Richard void main() { int i=0; typedef struct data a; printf("Enter the no. of data slots you want to make\n"); //scanf("%d",&slot); //commented here a c[slot]; for (i=0;i<slot;i++) { printf("Enter the Owner's Name\n"); //gets(c[i].oname); scanf("%s",c[i].oname); //&c[i].oname[20] not necessary printf("Enter the chassis number\n"); scanf("%d",&(c[i].chno)); printf("Enter the model year\n"); scanf("%d",&(c[i].model)); printf("Enter the brand name\n"); //gets(c[i].brand); scanf("%s",c[i].brand); //&c[i].brand[20] not necessary } for (i=0;i<slot;i++) { printf("%s %d %d %s\n",c[i].oname, c[i].chno,c[i].model,c[i].brand); } getche(); }
kanduripavan
Posts
-
Structures Printing -
Looking for a suitable zip lib which can access subdirectoryTry with 7zip sdk. I am not sure but give a shot.
-
Worker thread->crashIts easy. I got it. All what u have to do is to put break point on the thread function(F9 For all the lines) debug and wait for the application to crash. Thats it.
-
Visual Studio BrowserI am not sure exactly in which place to edit. Is you machine is connected to a Network (Lan or wan or anything) if it so then there will be a file in which you will be giving the host name list. there you have to go and and remove the unwanted ip. that may solve your problem. I am sorry i cannot recollect the file name. I m extremely sorry for my poor memory.
-
Urgent!! Please HelpI have few things to say. Check if you have any Memory profiler tools nearby available to you. Such as Rational purify or something else even one from codeproject. Run your code once. That will fix your problem. You will definitely get the location where u are going wrong. Have patience. I know its too hard, but its the truth.
-
Multithread and GDI Issueshi , Thats great as what you said. The problem was in creating the dc. The code was
void CThreadDemoView::OnMenuOffline()
{
// TODO: Add your command handler code here
CClientDC dc(this);
CreateThreadsToPlot(pDC, CPoint(100,100) );
}CreateThreadsToPlot will create the required no of threads to plot the points. After seeing your reply i tried this as a last attempt before giving it up. I went and browsed into the gdi code and found that my dc was not null. but surprisingly i think its invalid. This could be probably one of the reason i might have got the assertion. The code change was
void CThreadDemoView::OnMenuOffline()
{
// TODO: Add your command handler code here
CDC* pDC =GetDC();//code changed here only
CreateThreadsToPlot((CDC*)pDC, CPoint(100,100) );
}This way of getting the DC has fixed the same issue without changing not even a single line of code in the program. Thank you very much Mr. Mark Salsbery. By, Manu
-
Multithread and GDI IssuesI have one one critical section shared by all the threads. I had Initialized the critical section before creating the child threads. I have 2 doubts. 1.The critical section is initialized by the UI Thread ie by the primary thread. So is it there it can go wrong. 2.Lets leave the GDI issue and consider the handle as a shared object which is inside the critcal section. SO how can the 2nd or the 3rd thread can enter and access it. As a beginner it seems for me that is is not logically valid. (the thread trying to acess gdi handles which is inside the critical section). I am extremely sorry to say these lines. The assertion is shown in GDI files. But as far as i know it occured due to the line dc.LineTo(pt1);//From here onwards the error might have occured I like to thank you for supporting the one who doesnt knows anything. Thank you.
-
Multithread and GDI IssuesHi, I did it as you said. It has fixed my problem of plotting multiple points simultaneously.
EnterCriticalSection(pMutex); { pt2=(CPoint) m_lstPoints.GetNext(pos); //CDC dc; //hdc is a CClientDC //dc.Attach(hdc);//I had even tried to Send CClientDC* directly //Plot code begins //Here we draw rectangles,lines or something using dc //dc.Moveto(pt1); //These lines are giving assertion //Plot code ends here //dc.Detach(); //GdiFlush(); //Instead of the above code i used pView->SendMessage(ID_VIEW_DRAWOFFLINE, (LPARAM)&pt1,(WPARAM)&pt2 ); LeaveCriticalSection(pMutex); }
Thank you very much Cédric Moonen, Mark Salsbery,Suman and others who looked after my issue. -
Multithread and GDI IssuesSir, Thank you very much. I am very much new to threading. I like to plot points without timer and using threads only. The output which i wanted was that each points has to be plotted individually. Nothing professional. i am just entering into this new world of threading and experiencing the problems of multi thread programming if i am going to implement in near future. I will try and implement the same and get back to you. I saw similar kind of codes in MTGDI but they are subclassed(CWinthread). I want to experiment if a particular section of the code is implemented by multiple threads then what will happen.What will happen to CList object poistion variables, and impact of other things. This is my intention. Thank you very much. Manu
-
Multithread and GDI IssuesSir, You got it. I am sorry to say this that i mentioned in the code with a comment where i am getting illegal or assertion dailog. ("//dc.Moveto(pt1); //These lines are giving assertion"). I am clearly and purposefully making my child threads to draw the lines. What is the alternative. More over i had initialized the critical section also. 1. Shall i ask the view to redraw the points by sending the points 2. or else i have to do something else. Thanks for answering my question. Regards, Manu
-
Multithread and GDI IssuesHi, I like to draw lines with delay but using threads. The data will be fetched from different list (m_lstpoints). they have to be drawn simultaneously. When i tried to do this i am getting illegal. I am very much new to threads. Can u help me. //Code CRITICAL_SECTION g_csGDILock; //Initialized AfxBeginThread(DrawStrokesUsingThrd, (LPVOID)pTInfo1); AfxBeginThread(DrawStrokesUsingThrd, (LPVOID)pTInfo2); AfxBeginThread(DrawStrokesUsingThrd, (LPVOID)pTInfo3);//This list is dynamic //The pTInfo contains the g_csGDILock pointer and other info //to draw points such as dc and list of points. void CPlotPoints::TDrawPoints(HDC hdc, PRTL_CRITICAL_SECTION pMutex){//Non static POSITION pos =NULL; CPoint pt1, pt2; pos =m_lstPoints.GetHeadPosition(); pt1=(CPoint) m_lstPoints.GetNext(pos); while (pos){ EnterCriticalSection(pMutex); { pt2=(CPoint) m_lstPoints.GetNext(pos); CDC dc; //hdc is a CClientDC dc.Attach(hdc);//I had even tried to Send CClientDC* directly //Plot code begins //Here we draw rectangles,lines or something using dc //dc.Moveto(pt1); //These lines are giving assertion //Plot code ends here dc.Detach(); GdiFlush(); } LeaveCriticalSection(pMutex); Sleep(300); } } Thank you. Manu
-
Using XML in MFCI had downloaded one version of msxml sdk,which ran perfectly alright in the release mode but not in the debug version. Faced similar difficulties like i was not able use the tlb (import lib). I then browsed and found that there was a patch for that release, so have to download that again and after then only i was able to build my application in debug mode. thats it.
-
Using XML in MFChi, I think u have to either download a patch which is available in ms patch downloads. I think the build of yours is a debug one, try in the release mode. becoz i faced similar problem when i downloaded the xml sdk. I am not sure , try this. If it works or not take it as a note. See u.
-
Update text on one form from another formhi, have a CClass* (of the class where u have to update) as a dialog box member. Before calling DoModal update this pointer and rest handle with the pointer. Try it.Lets see . Have a nice day
-
ON_NOTIFY_RANGE problem!ON_CONTROL_RANGE try this. I hope it will solve the problem
-
VistaTry to login in Pure Admin user and then see. I hope it will work definitely. Try it.
-
Word data transferCan i know what is meant by 'its messing the clipboard' so that if can clearly loook into your issue.
-
How to get handle to main frame in CDocumentuse AfxGetMainWnd();and typecast to the mainframe pointer. I dont know if it works or not just give a try.if its not working we will try again.
-
Create processPROCESS_INFORMATION prcInfo; STARTUPINFO startupInfo; memset(&prcInfo, 0, sizeof(PROCESS_INFORMATION) ); memset(&startupInfo, 0, sizeof(STARTUPINFO ) ); startupInfo.cb = sizeof (STARTUPINFO ); //DEBUG_ONLY_THIS_PROCESS BOOL blnStatus = CreateProcess("e:\\temp\\samp.bat", NULL, //CreateProcess("c:\\winnt\\system32\\calc.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &prcInfo); if (blnStatus ) { STILL_ACTIVE DWORD dwExitCode=0; BOOL blnExit = GetExitCodeProcess(prcInfo.hProcess, &dwExitCode); WaitForSingleObject(prcInfo.hProcess, INFINITE); blnExit = GetExitCodeProcess(prcInfo.hProcess, &dwExitCode); dwExitCode=0; AfxMessageBox("Hello Fin",MB_OK); CloseHandle(prcInfo.hProcess); //This is the code that i had tested working fine for me. // i tested in both the case in which the first one i called //the executable file directly, in the second time i called //using a batch file. The next statement of WaitForSingleObject is watiting actuall to end its process.
-
2 Errors: 1. unresolved externals...I think your project settings are getting changed. sometimes it happens with the VS. I think there is problem with the dsp file i am not sure of it in your case.