-
Stupid pointer array function problem thing
lol so I'm working on this useless program to convert text to litelite 1337, but that's not the important part. I'm in a life and death battle of syntax with this thing. I'm using DEv-c++ and this is my code. everything but the trans() works. I'm sure i'm doing this really badly but I'd appreciate any constructive criticism. Ty in advance :)
Code:
char* wtoc(char* Dest, TCHAR* Source, int SourceSize )
{
for(int i = 0; i < 512; i++)
Dest[i] = (CHAR) Source[i];
//wcstombs(strTo,strFrom, SIZE);
return Dest;
}
void tran(char *mytext[])
{
char returner[512];
int i = 0;
while( i < 512 )
{
if( *mytext[i] == 'a')
{
returner[i] = '@';
}
if( *mytext[i] == 'b')
{
returner[i] = 'B';
}
if( *mytext[i] == 'c')
{
returner[i] = '(';
}
if( *mytext[i] == 'd')
{
returner[i] = 'Ð';
}
if( *mytext[i] == 'e')
{
returner[i] = '3';
}
if( *mytext[i] == 'f')
{
returner[i] = 'F';
}
if( *mytext[i] == 'g')
{
returner[i] = 'G';
}
i += 1;
}
*mytext = returner;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndEdit;
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
static TCHAR szText[512] = "";
switch (message) /* handle the messages */
{
case WM_CREATE:
hwndEdit = CreateWindow(TEXT("edit"), NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER,
10, 10, 500, 20, hwnd, (HMENU) ID_EDIT,
((LPCREATESTRUCT) lParam)->hInstance, NULL);
case WM_COMMAND:
if(LOWORD(wParam) == ID_EDIT)
{
if(HIWORD(wParam) == EN_ERRSPACE || HIWORD(wParam) == EN_MAXTEXT)
MessageBox(hwnd, TEXT("Edit control out of space!"),
"tranny", MB_OK | MB_ICONSTOP);
if(HIWORD(wParam) == EN_UPDATE)
{
GetWindowText(hwndEdit, szText, 511);
InvalidateRect(hwnd, NULL, TRUE);
}
}
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
char *text;
wtoc(text, szText, 512);
tran(&text);
DrawText(hdc, text, -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hwnd, &ps);
return 0;
//blah
return 0;
}
-
looks like a scope problem. your return variable is destroyed when function exits (consider static keyword) which creates problems. Alternately, modify the input variable directly instead of playing with the pointers which is risky.
-
First off, you can't assign arrays in C++. You can only assign pointers, but that's not the same thing as copying an entire array. Secondly, returner is a local automatic array which gets destroyed when tran() returns so whatever you've written into returner has been destroyed when trans returns.
Instead of using arrays an pointers, you can use a string object. However, if you prefer to use char arrays, use memcpy to copy returner to mytext[0]
memcpy(mytext[0], returner, sizeof(returner));
Finally, don;t forget to initialize returner (and every other variable):
char returner[512]={0};
Danny Kalev
-
thank you both, I ended up just putting the translation code before I drew the text, instead of messing with passing array arguments and returning arrays or whatever. thanks again :)
Similar Threads
-
By AustinMontoya in forum C++
Replies: 1
Last Post: 11-05-2006, 09:55 PM
-
Replies: 0
Last Post: 07-20-2002, 10:12 PM
-
By Sonia Kumar in forum VB Classic
Replies: 4
Last Post: 07-10-2001, 12:45 PM
-
By Sonia Kumar in forum VB Classic
Replies: 0
Last Post: 07-09-2001, 06:51 AM
-
By Michael Shutt in forum VB Classic
Replies: 6
Last Post: 04-05-2001, 02:25 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks