NO

Author Topic: Wierd Behaviour...  (Read 5606 times)

jcarr

  • Guest
Wierd Behaviour...
« on: June 11, 2007, 12:12:32 PM »
Im writing a program and I keep getting wierd output...
What the following does is takes a filepath opened cuts out the path, leaving only the filename then adds a tab with that as a caption. The problem is the routine that cuts off the path. Im scratching my head trying to figure it out. Any help is appreciated.

I have noticed though it works fine on filenames WITHOUT spaces. Then one with a space does work but the next one after will have extra characters added to the front  ???
in main.c:
Code: [Select]
...
#include "JSTRING.h"
#define INFIN 99999
...
int openfile(file[]){
...
// tabs
char fname[INFIN];
strcpy(fname, "");

j_rempath(temp, fname);

addTab(fname); // this line is irrelevant...
...
}
...

in JSTRING.h:
Code: [Select]
#define J_INFIN 99999
...
// removes the path of a filepath
void j_rempath(char* fullpath, char* buff){
char temp[J_INFIN];
j_getpath(fullpath, temp);
int lenfull = strlen(fullpath);
int lenpath = strlen(temp);
int lenfile = lenfull - lenpath;
strcpy(buff, "");

j_right(fullpath, buff, lenfile);

strcpy(fullpath, "");
lenfile = 0;
lenpath = 0;
lenfull = 0;
}
...
// returns the n characters from the right of a string
void j_right(char* in, char* buff, int n)
{
_strrev(in);
strcpy(buff, "");
strncpy(buff, in, n);
_strrev(buff);
}
...

Note that ... represents unused code in this section of work.

thanks :D

jcarr

JohnF

  • Guest
Re: Wierd Behaviour...
« Reply #1 on: June 11, 2007, 01:16:43 PM »
Are you just trying to separate the filename? If so the following will do it. You did not include the function j_getpath so could not run your code.

The following might be improved with some error checks.

Code: [Select]
char * j_rempath(char * fullpath)
{
char * p = fullpath + strlen(fullpath);
while(*p != '\\')
{
p--;
}
return(++p);
}

int main(void)
{
char path[] = "C:\\WINDOWS\\Cursors\\gnwse.dat";
char buf[256];
strcpy(buf, j_rempath(path));
printf("%s\n", buf);
return 0;
}

John

jcarr

  • Guest
Re: Wierd Behaviour...
« Reply #2 on: June 12, 2007, 04:15:23 AM »
Ah yeah sorry I forgot to include j_getpath(), my bad :D

Thanks I will try the new method  ;)

jcarr

jcarr

  • Guest
Re: Wierd Behaviour...
« Reply #3 on: June 14, 2007, 08:26:22 AM »
ok thanks :D

That works perfectly.
Now what I cant seem to get to work is:
Code: [Select]
case WM_NOTIFY:
switch (LOWORD(wParam)) {
// TAB CONTROL NOTIFICATIONS
case TCN_SELCHANGE: {
MessageBoxA(0, "Changed!!", "- Notice -", MB_OK);
int iTab = TabCtrl_GetCurSel(hTab);
//displayNewText(iTab);
}
break;
}
break;
The resource I got it from does exactly that... but it doesnt work :(

thanks

jcarr

JohnF

  • Guest
Re: Wierd Behaviour...
« Reply #4 on: June 14, 2007, 09:53:00 AM »
EDIT:

Here is some code that I just checked.

Code: [Select]
case WM_NOTIFY:
{
    NMHDR *lpnmhdr = (LPNMHDR)lParam;
    HWND hTab = GetDlgItem(hwndDlg, TAB_CONTROL_1);
    switch (lpnmhdr->code)
    {
        case TCN_SELCHANGE:
        {
            char s[90];
            sprintf(s, "Which Tab -- %d", TabCtrl_GetCurSel(hTab));
            SetWindowText(hwndDlg, s);
        }
        break;
    }
    break;
}

John
« Last Edit: June 14, 2007, 11:48:58 AM by JohnF »

jcarr

  • Guest
Re: Wierd Behaviour...
« Reply #5 on: June 15, 2007, 06:01:13 AM »
Thanks heaps it works perfectly  8)

However i don't know why that one works and mine doesnt  :-\

Ah well...

jcarr

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Wierd Behaviour...
« Reply #6 on: June 15, 2007, 07:02:01 AM »
WM_NOTIFY
    idCtrl = (int) wParam;
    pnmh = (LPNMHDR) lParam;

May the source be with you