|
Don't try to do it without the typedef. Using the typedef makes the code easier to understand.
Well, ok, to answer, I think the cast would be (char (*)[10]). But honestly, only Bjarne Stroustroup would know what that means. Stick with the typedef.
--Mike--
http://home.inreach.com/mdunn/
#include "buffy_sig"
|
|
|
|
|
Won't forget that in a hurry-it works, thanx Mike. I did try (char*)[10] - this didn't work, though I thought that was intuitive Looks like the right to left rule of reading declarations might come in handy even in areas such as this!
Cheers,
Shanker.
|
|
|
|
|
#include <iostream.h>
#include <string.h>
void main()
{
char *pstr="test" ;
cout<<strrev(pstr)<<endl;
}
This program isn't executed in VC++6.0, but in C++ Builder5.0, Why?
|
|
|
|
|
#include <iostream.h>
#include <string.h>
void main()
{
char *pstr="test" ;
cout<<strrev(pstr)<<endl;
}
OK, then Borland is not comforming to C. You wrote code that is attempting to modify a constant string. _strrev actually modifies the character array/pointer, so an error occurs here because you are modifying a constant. The correct way of doing this problem would be:
#include <iostream.h>
#include <string.h>
void main()
{
char str[] = "test";
cout << _strrev(str) << endl;
}
Frank
|
|
|
|
|
Thanks, Frank.
There is another question .
The program taken from an article "A Sample Generic-Text Program" from MSDN isn't executed in VC++ 6.0 , Whether it modifies a constant string either?
#include <stdio.h >
#include <stdlib.h >
#include <string.h >
#include <direct.h >
#include <errno.h >
#include <tchar.h >
int __cdecl _tmain(int argc, _TCHAR **argv, _TCHAR **envp)
{
_TCHAR buff[_MAX_PATH];
_TCHAR *str = _T("Astring");
char *amsg = "Reversed";
wchar_t *wmsg = L"Is";
#ifdef _UNICODE
printf("Unicode version\n");
#else /* _UNICODE */
#ifdef _MBCS
printf("MBCS version\n");
#else
printf("SBCS version\n");
#endif
#endif /* _UNICODE */
if (_tgetcwd(buff, _MAX_PATH) == NULL)
printf("Can't Get Current Directory - errno=%d\n", errno);
else
_tprintf(_T("Current Directory is '%s'\n"), buff);
_tprintf(_T("'%s' %hs %ls:\n"), str, amsg, wmsg);
_tprintf(_T("'%s'\n"), _tcsrev(str));
return 0;
}
|
|
|
|
|
Because when you declare:
TCHAR* str = "blah blah";
the literal string "blah blah" is stored in the executable. When loaded into memory, that string may, at the whim of the OS, be stored in a read-only section of memory. Thus your program fails when it tries to modify the string.
--Mike--
http://home.inreach.com/mdunn/
#include "buffy_sig"
|
|
|
|
|
Same Problem.
_TCHAR *str = _T("Astring");
is a pointer to a string constant. What you really want is
_TCHAR str[] = _T("Astring");
This will store the string into an array. Therefore, it allows _tcsrev (or now _wcsrev) to modify the array. Of course, I can't say that it's "ANSI C" because this is a MS-specific type.
Heh, it seems that the sample program is trying to get away with this business. In practice, you should never modify a pointer to a constant string.
Frank
|
|
|
|
|
#include <iostream.h>
#include <string.h>
void main()
{
char *pstr = new char[5];
strcpy(pstr,"test");
cout<< strrev(pstr) <
|
|
|
|
|
How Can convert BSTR to LPCSTR OR vice versa!
|
|
|
|
|
CString does it for you - it can be constructed from a BSTR and AllocSysString returns a BSTR.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Use _bstr_t to handle conversion from BSTR to const wchar_t*/const char*. _bstr_t is part of VC6.0's compiler COM support classes. Defined in <comdef.h>.
--
Venkat
|
|
|
|
|
Define USES_CONVERSION; at the top of the method implementation you are trying to do the conversion in. then use W2T
void foo(BSTR bstrVariable)
{
USES_CONVERSION;
// conversion is done to the stack so don't delete on function exit
// and don't use pointer outside of method.
LPCTSTR pcstrVariable = W2T(bstrVariable);
// TODO: do work with string.
}
Cheers,
-Erik
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
My thoughts are my own and reflect on no other.
|
|
|
|
|
Can any one please provide me with a way to enable the inserting of tabs into a RichEdit control within a dialog based application. The rich edit control is contained within a tab control page therefore the normal action when the tab key is pressed is to tab to the next tab in the control.
|
|
|
|
|
Is there a function that can convert a CString containing a hexadecimal or octal string to an integer. atoi() only works for decimal strings.
---
Multitasking: Screwing up several things at once.
|
|
|
|
|
|
|
Hi,
I have a MDI application, and I can display bitmaps and draw lines..
Lets say that I do everything that I wanna do on the first document.
I like to use to same data( lines, points) on my next document..
how can i do that?
Thanks
Ehsan Behboudi
|
|
|
|
|
Here is a way of iterating through your open documents:
CWinApp* pApp = AfxGetApp();
POSITION posTemplate = pApp->GetFirstDocTemplatePosition();
while (posTemplate)
{
CDocTemplate* pTemplate = pApp->GetNextDocTemplate(posTemplate);
POSITION posDocument = pTemplate->GetFirstDocPosition();
while(posDocument)
{
CDocument* pDoc = pTemplate->GetNextDoc(posDocument);
if (pDoc)
{
Having done so, there is no reason you'd have any problems copying data from one document to another.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
thanks for your reply,,
I like to know,if this is a way of only copying data from an open document to another,
or having access to the open document's data,, or both??
In my application i need to have access to the data too.
another question:
Does this mean that I have to use serialization method in my application?
thanks
Ehsan Behboudi
|
|
|
|
|
If you have the pointer to the document, then you have access to the data ( or at least get methods ). You can use GetActiveDocument() to get a pointer to the current active document, use the code I gave you before to get access to another document, and then copy between them.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
I know that the Submit and Preview buttons don't look the same but I still managed to hit the wrong one. Will try again with the question.
OK, I am still working on my ground breaking Dialog based database application. Answers to my previous questions have allowed me to get things working the way I wanted but as always I have found another annoyance I can't work around.
In the summary screen for say Customers I fill the ListCtrl with data returned by a
SELECT *
FROM
CUSTOMERS
of course this means that the first column contains the Primary Key which I don't need the user to see. I could select each column except the Primary Key individually to fix this but this leads me to another problem. When a user selects a row to Delete a Customer I use the value in the first column as the key to delete the correct record.
So what I want is to Hide the first column containing the key so the user can't see it but still have it returned by GetItemText when I need the key to Delete or Update.
Can this be done?
Can some kind developer give me the function?
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|
|
Are the customer names unique ? If so, you could build a map to hold the key. Maps rule.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
You can do this by the clistctrl function - setitemdata();
instead of insertcolumn
example:
m_lst.setitemdata(0,/*the unique customer id*/);
|
|
|
|
|
You can always set the Primary Key column's width to 0, thereby making it hidden.
LVCOLUMN lvColumn;
memset(&lvColumn, 0, sizeof(lvColumn));
lvColumn.mask = LVCF_WIDTH;
listCtrl.GetColumn(0, &lvColumn);
lvColumn.cx = 0;
listCtrl.SetColumn(0, &lvColumn);
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
OK, I am still working on my ground breaking Dialog based database application. Answers to my previous questions have allowed me to get things working the way I wanted but as always I have found another annoyance I can't work around.
In the summary screen for say Customers I fill the ListCtrl with data returned by a
SELECT *
FROM
CUSTOMERS
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|