-
weird strings
i made this to separate the string argument created from a drag and drop. but i'm not sure why the 'justpath' prints extra charactors after the path?. hope you see what i mean from the code. i tryed adding NULL thingy to the end but this didn't help.
Code:
#include <stdio.h>
main(argc,argv)
int argc;
char *argv[];
{
int go,go2,pathlen;
char *path,*filename,*extention,*justpath;
path=(char*)malloc(60);
filename=(char*)malloc(20);
extention=(char*)malloc(10);
pathlen=strlen(argv[1]);
path=argv[1];
printf("value of [argv[0]]= %s\n",argv[0]);
printf("value of [argv[1]]= %s\n",argv[1]);
printf("amount of arguments[argc]= %d\n\n",argc);
printf("path length= %d\n",pathlen);
printf("name of [path]= %s\n",path);
printf("starting address of [path]= %p\n",path);
for(go=pathlen;path[go]!='.';go--){
printf("%d: to the dot [path[go]]= %c\n",go,path[go]);
}
for(go2=pathlen;path[go2]!='\\';go2--);
strncpy(extention,path+go,5);
printf("\n extention == %s\n",extention);
printf("starting address of [exten]= %p\n",extention);
strncpy(filename,path+go2,20);
printf("\n filename == %s\n",filename);
printf("starting address of [file]= %p\n",filename);
strncpy(justpath,path,go2);
//strcat(justpath,"\0");
printf("\n justpath == %s\n",justpath);
printf("starting address of [justpath]= %p\n",justpath);
return(0);}
-
You'll have to be a bit more specific. What type of program is this, and what is this drag and drop program? If you know what the length of the string is, add a null character to the end based on that. Otherwise, with your current method, you could be placing the null after the extra characters. This would also be cause by have an array that wasn't initialized properly, or was initialized to be too big. What you should do is create a blank array first, and then filling it with the data. Make it blank by having every element contain \0, otherwise you'll end up with a bunch of characters that just depend on what was in memory last time it was used.
-
its not really a program in its self but a function for a program. the main program just converts a files binary data into a format a C program can use. this works fine but you have to type the file name and its this i want to get rid of. i also want to use this data, location etc.. and transfer it to the output file.
-
Again, you'll have to be more specific. First of all, what is the drag and drop for? What kind of program is this function for? Why are they typing the program path? Why do you want to get rid of it?
-
while working on what you said in your first post i discovered i didn't allocate memory to the justpath variable. i'm sorry i was clear about the drag and drop i was on about how you can drag the file icon other the program icon and it would send the files path and name as a string to the second argument.
sorry to waste your time but what you've said has helped. thanks.
-
lol - No problem. Glad I could help.