|
I would suggest that you read up and experiment a little on CString . CString will give you everything that you need.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
See here [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hi..
If i want to print after Administrator then what to do
"https://testsrv1.ifit.com/Exchange/Administrator/Inbox">https://testsrv1.ifit.com/Exchange/Administrator/Inbox/Example.jpg"
//////////////////////////////////////////////////
I should get the result in this way
"https://testsrv1.ifit.com/Exchange/Administrator/Inbox">https://testsrv1.ifit.com/Exchange/Administrator/Example.jpg"
Required to find /Inbox/Example.jpg
thank you
Hi,,
I am sharan.Working as a software Engineer in Indo-Fuji Software Company located in BTM Layout.Bangalore.India.
I have Completed my B.E(COmputers)in 2006.ANd I am having 2 years of Exp in VC++.
thanking you
sharan
|
|
|
|
|
Please do not post the same thing over and over. Try doing something yourself.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Here is an example*:
CString str = _T("Path/Old.jpg");
int iPos = str.ReverseFind('/');
str.Delete(iPos,str.GetLength()-iPos);
str += "/New.jpg";
AfxMessageBox(str);
*This example uses the esoteric ReverseFind() method.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
sharanu wrote: #Sample.jpg#TSXGMP850_EN_V10.pdf
Will the pattern of the string be same all the time? If it won't, then you may need to write a generalised approach.
Assuming that the pattern of the string will be the same, here is a way to do what you want:
CString str = _T("#Sample.jpg#TSXGMP850_EN_V10.pdf");
CString str1, str2;
int iPos = str.ReverseFind('#');
str2 = str.Mid(iPos+1);
str1 = str.Left(iPos);
str1.Remove('#');
AfxMessageBox(str1);
AfxMessageBox(str2);
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
If you are using MFC, see if AfxExtractSubString() will work for you.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can any one tell me that ..How to do Asynchronous Data Transfer through Serial Port.
Event based Serial communication,,,that means when any data come from serial port then,the particular function need to be called!!!!
the program does not wait long time for any data coming from Serial port.
Somebody suggested use callback functions!!!!!!but how?????
thanks in advance..
|
|
|
|
|
|
Hey everybody,
I'm using MS Visual C++ 6.0
I do have a code which contains classes in classes. Most inner class has a char** pointer which allocates memory using malloc function and adds a char array to string array.
To be more specific:
<br />
a = (char**) calloc(10, sizeof(char));
<br />
for (int i = 0; i < 10; i++)<br />
{<br />
a[i] = (char*) calloc(10 , sizeof(char));
}<br />
the problem is I want a destructor which free this array.
Says Access Violation each time I try to execute.
here is my code:
<br />
#include "stdafx.h"<br />
#include <malloc.h><br />
#include <stdio.h><br />
#include <conio.h><br />
<br />
<br />
class sub<br />
{<br />
public:<br />
char** a;<br />
<br />
sub();<br />
~sub();<br />
};<br />
<br />
<br />
sub::sub()<br />
{<br />
a = (char**) calloc(10, sizeof(char));<br />
<br />
for (int i = 0; i < 10; i++)<br />
{<br />
a[i] = (char*) calloc(10 , sizeof(char));<br />
}<br />
<br />
printf("\n%x - %x - %x\n", a[0], &a[0], *a[0]);<br />
};<br />
<br />
sub::~sub()<br />
{<br />
for (int i = 0; i < 50; i++)<br />
{<br />
char** A = a;<br />
char* Ai = a[i];<br />
char* Aii = (char *)*((int*)a[i]);<br />
<br />
free(a[i]);
}<br />
};<br />
<br />
<br />
class allocater<br />
{<br />
public:<br />
sub** subs;<br />
<br />
allocater();<br />
~allocater();<br />
<br />
};<br />
<br />
allocater::allocater()<br />
{<br />
subs = (sub**) calloc(10, sizeof(subs));<br />
int i; <br />
<br />
for (i = 0; i < 10; i++)<br />
{<br />
subs[i] = new sub();<br />
}<br />
};<br />
<br />
<br />
allocater::~allocater()<br />
{<br />
int i; <br />
<br />
printf("destructor allocater");<br />
<br />
for (i = 0; i < 10; i++)<br />
{<br />
delete subs[i];<br />
}<br />
};<br />
<br />
<br />
void main(int argc, char* argv[])<br />
{<br />
allocater** a = (allocater**) calloc(10, sizeof(allocater));<br />
int i;<br />
<br />
for (i = 0; i < 10; i++)<br />
{<br />
a[i] = new allocater();<br />
}<br />
<br />
printf("allocated");<br />
<br />
<br />
<br />
<br />
<br />
for (i = 0; i < 10; i++)<br />
{<br />
delete a[i];<br />
}<br />
<br />
<br />
printf("freed");<br />
<br />
getch();<br />
<br />
}<br />
Thank you everyone..
|
|
|
|
|
If you are writing C++ code (you are using classes, which is C++ specific), why do you still want to use C functions like malloc ? Prefer the use of new and delete instead.
|
|
|
|
|
dehseth wrote: sub::sub()
{
a = (char**) calloc(10, sizeof(char));
for (int i = 0; i < 10; i++)
{
a[i] = (char*) calloc(10 , sizeof(char));
}
printf("\n%x - %x - %x\n", a[0], &a[0], *a[0]);
};
sub::~sub()
{
for (int i = 0; i < 50; i++)
{
char** A = a;
char* Ai = a[i];
char* Aii = (char *)*((int*)a[i]);
free(a[i]); // crash point
}
};
you are allocating 10 items (for (int i = 0; i < 10; ) and freeing 50 items (for (int i = 0; i < 50; ) and what you are trying to achieve with char* Aii = (char *)*((int*)a[i]); and you are not freeing the first dimension array "a" in sub and in main(). I prefer you to learn the concepts clearly
|
|
|
|
|
Hi,
Like Cedric has mentioned you should try to use thew new and delete.
dehseth wrote:
a = (char**) calloc(10, sizeof(char)); // main array
for (int i = 0; i < 10; i++)
{
a[i] = (char*) calloc(10 , sizeof(char)); // char arrays
}
a has a size of 10 bytes (calloc(10, sizeof(char)) = 10 * 1 byte) but to
store 10 pointers you need 40 byte since a pointer has a 4 byte size (sizeof(int)).
Rewrite the allocation of a:
a = (char**) calloc(10, sizeof(int));
But again you should try to use the new and delete.
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
BadKarma wrote: a = (char**) calloc(10, sizeof(int));
what about sizeof (char *)
|
|
|
|
|
Good question.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
char* Aii = (char *)*((int*)a[i]);
What is This?
char* Aii = (char *)((int*)a[i]);
|
|
|
|
|
|
Why are you using pure C here?
As you program C++, try to use C++ structures.
Like a std::vector of std::strings .
Or the MFC-class CStringArray.
Also, input and output is much easier using the predefined IOStreams std::cin and std::cout !
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
You make the same error on each allocation:
For instance your code is
dehseth wrote: a = (char**) calloc(10, sizeof(char));
but a is declared as follows
char ** a;
hence you must allocate memory this way
a = (char**) calloc(10, sizeof(char <big>*</big>));
Please note the * operator inside sizeof .
BTW as Cedric Moonen already stated, in C++ language, new is the preferred way to allocate memory.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
First of all thank you everyone!
I am writing the code in DLL, and this was not the actual code. I need malloc and calloc and free in my code.
Problem solved by using * in sizeof functions. As an example:
previous code:
allocater** a = (allocater**) calloc(10, sizeof(allocater));
new code:
allocater** a = (allocater**) calloc(10, sizeof(allocater<big>*</big>));
I forgot that 50 in loop since I have tried too many things I guess.
I should have noticed this
Thank you everybody again.
Let's keep movin'
|
|
|
|
|
dehseth wrote: free(a[i]); // crash point
What is the value of i ?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Problem has been solved. i is the loop integer which gets values from zero to ten in given example code.
|
|
|
|
|
dehseth wrote: i is the loop integer which gets values from zero to ten in given example code.
Actually, it was being incremented to 50, hence the crash and my question.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
CString csSql= "update [MY_TABLE]"
" set"
" STRING_0 = \'hello\', "
" TIME_0 = \'02/30/2008 12:5:7\'"
" where"
" TABLE_ID = 10"
" and ITEM_ID = 100"
" and TIME_0 = \'01/24/2008 7:10:33\'"
;
//===============================================
When the SQL is executed, an error says:
Data type mismatch in criteral expression (3464)
//===============================================
when I delete last line of the SQL statement
" and TIME_0 = \'01/24/2008 7:10:33\'"
the SQL statement becomes OK.
type of field TIME_0 is Date/Time.
what is wrong?
any sample code for using Date/Time in 'where' of 'update ... set ...' statement?
thanks
|
|
|
|
|
Have you tried displaying the csSql string with a message box and verified that the SQL statement is perfect before executing it on the DB?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|