My object is to read the text file containing the name and ages of the students, character by character and then store them in a structure. (For test purpose I want to store just one record) I wrote the following code but it is giving an error "aggregate'main():: record r' has incomplete type and cannot be defined". Why is this?
fp = fopen("records.txt","rb");
if(fp == NULL)
puts("Cannot open file");
};struct record r;
if (isdigit(ch[n])&& ch[n-1]==32)
i need an edit ctrl for entering numerical values. sometimes these values must lie in a specified range. otherwise, i want to warn the user by changing the edit-box color.
i derived a class from CEdit for this purpose and tried to put the code in the CtlColor:
HBRUSH MyEdit::CtlColor(CDC* pDC, UINT nCtlColor)
if (d_chars==decimalChars) // if mode==emDecimal
if (val<d_minVal || val>d_maxVal)
i don't need to change the default brush used for painting the ctrl, so i return NULL. but this doesn't work. i tried returning a valid handle to a brush i created, but i could at most change the background color, not the text color.
what's the problem?
what's the best solution?
This is not correct. WM_CTLCOLOR is sent to the parent window.
So you should be handling OnCtlColor of the parent dialog.
In that, check if the message is for your particular edit control and then do pDC->SetTextColor.
«_Superman_» I love work. It gives me something to do between weekends.
I have created an MFC app as a SDI supporting doucment/view architecture. The main classes are: CMainFrame, CView, and CDocument. In my app I want to dynamically create a CListView when the user select a menu item. I've added CListView class to my project. In my OnInitialUpdate() I'm doing InsertColumn() calls and in OnUpdate() I'm doing InsertItem() and SetItemText(). When a menu item is select I am basically set a point to a new CListView object. What is not working is that nothing is being displayed on the screen !!! I know once the memory is allocated for the new CListView object I need to call Create() function. Don't know what I need to pass or how to link this to my CView class so that it is acutally displayed. Please help. I have not seen any good examples on dynamically creating a CListView object.
But the 'sizeof' command is returning the value '1'
It returns 1 and that is correct, because this is the size of a char type.
If you need the count of the elements in array, you have to use _countof macro -> here.[^]
This form here: count = _countof(ch) will always return 100, because you actualy allocated memory for 100 elements on the stack. But note that the variable "n" from your code holds the count of the characters.
Also note that your use of sizeof is wrong. If you need the size of an array in bytes, than you must change it to: sizeof(ch).
If by 'whatever input' you mean the number you put in the square brackets for ch, I think this is because ch[n] is always going to be a pointer. It's equivalent to char *ch = (char*)malloc(sizeof(char) * n);
then sizeof(ch) will always be 1 because it's pointing to the start of your array. In C, you sort of always have to keep track of the size of your arrays manually.
ch is a pointer, ch[n] is one character out of an array of characters, that is why its size is 1.
Luc Pattyn [Forum Guidelines][My Articles] DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
OK - that's not how sizeof works - it tells you the size of a type, either via the typename ('sizeof (char)') or a compile-time static expression ('sizeof (3 * 4.0)'). The WIkipedia entry[^] is quite accurate.
I presume you know you can use n to tell you how many characters have been entered...
printf("\n\nWant to delete the array?");
Can I suggest you read up how strings (specifically null terminated strings) and arrays work in C?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Last Visit: 31-Dec-99 19:00 Last Update: 13-Feb-16 12:54