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:...
#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:#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
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.
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
Ah yeah sorry I forgot to include j_getpath(), my bad :D
Thanks I will try the new method ;)
jcarr
ok thanks :D
That works perfectly.
Now what I cant seem to get to work is: 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
EDIT:
Here is some code that I just checked.
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
Thanks heaps it works perfectly 8)
However i don't know why that one works and mine doesnt :-\
Ah well...
jcarr
WM_NOTIFY
idCtrl = (int) wParam;
pnmh = (LPNMHDR) lParam;