|
Hi all,
Is it possible to use the strncpy() function to achive the following:
FileName1.txt to FileName1.abc
I have tried the following:
<code>
int ExtensionLen;
char *ExtensionString;
ExtensionString = FileNameFromClient;
ExtensionLen = strlen(ExtensionString) - 4;
char extstring[20];
strncpy( (char*)extstring, ExtensionString, ExtensionLen );
strcat((char*)extstring,(char*)".tcp");
</code>
Just to change the extension, or is there something else I could use?
Thanx
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
If you want to do it in plain old C, here is a way:
char fileName[20];
strcpy(fileName, "FileName1.txt");
// Now change extension to ".abc"
// "Smart" coding, assumes there is a dot in the filename
strcpy(strrchr(fileName, '.'), ".txt");
OR (safer):
char * cpDot = strrchr(fileName, '.');
if(NULL != cpDot) strcpy(cpDot, ".txt");
Let the flaming begin! (I won't answer, I have work to do).
-- modified at 8:30 Thursday 16th November, 2006
Thanks, toxcct!
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
this will do if the file name contains only one '.'.
if the file is called for instance foo.test.doc, your code will fail.
|
|
|
|
|
Thanks for pointing that out. It's fixed now.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
Thank you toxcct ...
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Thank you kakan for the reply, I'll try it. And I don't think this senario will happen:
file1.a.txt
Thanx again
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Hello.
Anyhow, I've fixed it, when toxcct pointer it out to me.
I changed strchr to strrchr.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
You want to rename file , dont you?
Have you come across this code from MSDN ?
#include <stdio.h>
void main( void )
{
int result;
char old[] = "RENAMER.OBJ", new[] = "RENAMER.JBO";
result = rename( old, new );
if( result != 0 )
printf( "Could not rename '%s'\n", old );
else
printf( "File '%s' renamed to '%s'\n", old, new );
}
-- modified at 6:34 Friday 17th November, 2006
Hey , come on. Let me know reason before voting me down.
|
|
|
|
|
prasad_som wrote: char new[] = "RENAMER.JBO";
new is a reserved keyword
|
|
|
|
|
Its 'c' code .
This is header comment from MSDN for posted code,
|
|
|
|
|
prasad_som wrote: Its 'c' code
ok, now you say it, but you didn't explain it previously, so i couldn't know.
|
|
|
|
|
Thank you for the reply prasad_som.
Yes, I want to rename the file ... well kinda, the thing is I wrote a tcp/ip client - server. And the client sends a file to the server, but the server must change the extension of the file when the file transfer begins and change it back to the original extension. The thing is all the code is dynamic and file paths & extension can change... tricky ....
Thanx again
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
hmmm.
You may like to have look at this for parsing file name
basic_string::rfind ,CString::ReverseFind . Look to lst '.' character, and change it to rquired.
|
|
|
|
|
Thank you very much ... I'll check it out...
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
prasad_som wrote: Look to lst '.' character, and change it to rquired.
Or use PathFindExtension() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Or use PathFindExtension().
Very true. My 5.
|
|
|
|
|
« Programm3r » wrote: Is it possible to use the strncpy() function to achive the following:
FileName1.txt to FileName1.abc
Why not just use PathRenameExtension() ?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I wand to read file form end to the start of the file...
byte by byte...
can anyone suggest me or provide me any sample code that helps me...??????
thanks in advance...
Savcejana Sukinobavanthu
Ashok.
|
|
|
|
|
You could do it with a for loop, find the length of the file in bytes (using a while loop or otherwise)
then do a for loop but backwards
for(int i=FileLength; i>=0; i -=1) {
//Read the file i number of bytes
}
|
|
|
|
|
Why do you need to do this? I would suggest reading the file into a buffer, and then reversing that buffer. It'll be much faster this way.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
or reading the file and inserting in the buffer at the beginning instead of at the end.
|
|
|
|
|
Maximilien wrote: or reading the file and inserting in the buffer at the beginning...
Which is how files are normally read.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I don't know, if I have to read a file in order, I will read a line ( for example, a text file ) and add the newly read line at the end of my "buffer".
if I want to read the file in reverse order, I might read the file in order and then sort internally what I have read, or try to read the file in reverse (from the end ) and add to the buffer at the end.
|
|
|
|
|
Thismay not be the proper forum for this posting so I appoligise in advance if I have got it wrong, but i am hoping that someone can help me with my problem.
The problem is that when using IM with PDFMDD11.lib (thrid party Libraries) and third party lib under VS2005 and I then try to link to the StaticMTDLL IM Libraries I am recieving link errors indicating objects already defined.
I believe that the problem is a conflict of some kind between the PDF image libraries for reading/writing TIFF, PNG, and JPEG files and the Imagemagic Libraries. Can anyone help me put with this and provide a solution if possable.
The errors read.
>log4cppD.lib(CategoryStream.obj) : warning LNK4075: ignoring
'/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
1>CORE_DB_magick_.lib(nt-base.obj) : error LNK2005: _DllMain@12 already
defined in MSVCRTD.lib(dllmain.obj)
1>CORE_DB_tiff_.lib(tif_error.obj) : error LNK2005: _TIFFSetErrorHandler
already defined in pdfMDD11.lib(tif_error.obj)
1>CORE_DB_tiff_.lib(tif_error.obj) : error LNK2005: _TIFFError already
defined in pdfMDD11.lib(tif_error.obj)
1>CORE_DB_tiff_.lib(tif_warning.obj) : error LNK2005: _TIFFSetWarningHandler
already defined in pdfMDD11.lib(tif_warning.obj)
1>CORE_DB_tiff_.lib(tif_warning.obj) : error LNK2005: _TIFFWarning already
defined in pdfMDD11.lib(tif_warning.obj)
1>CORE_DB_png_.lib(pngvcrd.obj) : error LNK2005: _png_mmx_support already
defined in pdfMDD11.lib(png.obj)
1>..\..\output\Debug\Controller_win.dll : fatal error LNK1169: one or more
multiply defined symbols found
Options that I have tried include the /FORCE switch usage on the Linker Command line. Any solution ideas would be welcomed
Many thanks
Nigel
|
|
|
|
|
hi
how to show percentage completion on progress bar?
thanks
|
|
|
|