Re: Proper use of code
On Feb 3, 1:10 am, joshturner1967 <joshturner1...@gmail.com> wrote:
I have the following c++ code
char **filename is passed and is allocated in the calling function as
char *filename = malloc(1000);
int randominteger;
char *zptr;
char qfilename[500];
char randomintegerchar[500];
char *mimetype;
char *tptr;
char *cfilepath;
mimetype = part->getMimeType(); //Get the file type
tptr = strrchr(mimetype, '/'); //Strip off the extra values from the
getmimetype call
strcpy(qfilename, "BaseTempFile"); //Start building the temp
filename
randominteger = rand(); ///Get a random number
sprintf(randomintegerchar, "%d.", randominteger); //Turn the number
into a string
//Build the filename
strcat(qfilename, randomintegerchar); //Add the random number to make
the filename to make it unique
strcat(qfilename, tptr+1);
zptr = qfilename;
strcpy(*filename, zptr); //passed back to update the import name
strcat(cfilepath,"\\");
strcat(cfilepath, *filename);
part->getContentToClientFile(cfilepath,1); //Puts the file out in the
directory
zptr = NULL;
This works just fine for me in release and debug mode but my user gets
a gpf as soon as he enters into the function.
Am I doing something incorrect? Not allocating something that should
be allocated? Any ideas?
Thanks Josh
I appreciate the replies
I know this sounds lame but I am mainly from the c world and don't
venture into the c++ realm to often. That is why I was using the
strcat and strcpy functions instead of std. I am not as famliar with
std but what I gather I can do the following
namespace std;
string qfilename;
string mimetype;
string cfilepath = "C:\\Value\\import";
string basetempfile = "basetempfile";
string themime;
string randomintegerchar;
int randominteger;
qfilename.append(basetempfile);
mimetype = part->getMimeType(); //Mimetype would be in format of image/
tif and I would need tif
themime = mimetype.find_last_of("/"); <----Would I use this function
call to extract tif out of mimetype?
randominteger = rand(); <-----Get a random number
itoa(randominteger, randomintegerchar, 10); <----Put random number to
a string
qfilename.copy(basetempfile); <--add the basename
qfilename.append(randomintegerchar);<---add the random number
qfilename.append(".");<----Add the period
qfilename.append(themime);-<Add the filetype
cfilepath.append("\\");
cfilepath.append(qfilename);-<----Add the filepath to the directory
part->getContentToClientFile(cfilepath,1); //Puts the file out in the
directory
First off does this look better or am I off track. If I am off track
could you tell me where and show me what I should be doing?
Secondly I would like to be able to update filename as well char
**filename from qfilename but using this new method I am confussed and
I dont want to switch between c and c++ and want to learn it
correctly.
I know this is second nature to you guys but I am still in the
learning phase and would appreciate your expert advice so as to be as
good as you guys one day
Thanks
Josh
qfilename.append(basetempfile);
mimetype = part->getMimeType();
{ Edits: quoted banner removed. -mod }
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]