Stupid pointer array function problem thing


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Stupid pointer array function problem thing

Hybrid View

  1. #1
    Join Date
    Apr 2004
    Location
    Pennsylvania
    Posts
    72

    Unhappy 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;
    }
    Daniel Borgman
    Founder, MAD Programming( MADtek )
    www.MadProgramming.biz.ly
    www.MadProgramming.byethost2.com
    Founder, Old Baby Pictures Skate( BP )
    www.obpskate.byethost12.com

  2. #2
    Join Date
    Dec 2003
    Posts
    3,366
    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.

  3. #3
    Join Date
    Nov 2003
    Posts
    4,118
    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

  4. #4
    Join Date
    Apr 2004
    Location
    Pennsylvania
    Posts
    72
    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 :)
    Daniel Borgman
    Founder, MAD Programming( MADtek )
    www.MadProgramming.biz.ly
    www.MadProgramming.byethost2.com
    Founder, Old Baby Pictures Skate( BP )
    www.obpskate.byethost12.com

Similar Threads

  1. Replies: 1
    Last Post: 11-05-2006, 09:55 PM
  2. Replies: 0
    Last Post: 07-20-2002, 10:12 PM
  3. Calling Dll Function by Function Pointer
    By Sonia Kumar in forum VB Classic
    Replies: 4
    Last Post: 07-10-2001, 12:45 PM
  4. Calling Dll Function by Function Pointer
    By Sonia Kumar in forum VB Classic
    Replies: 0
    Last Post: 07-09-2001, 06:51 AM
  5. calling ping thru vb
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center