|
char *ID;
char Buffer[20];
int abc = 10;
itoa( abc , Buffer , 10 );
ID = new char[strlen(Buffer) + 2];
ID=Buffer;
strcat(ID ,"c");
cout<<"Value="<<id<<"\n";
<font="" size="2" color="#99ff66">
whitesky
|
|
|
|
|
i hope i am not troubleing u >.<
now the output is 10c i am trying to get c10 >.<
i already tried this:
ID="c";
strcat(ID ,Buffer);
got error...
|
|
|
|
|
well ok i mistake i think your problem is itoa so its easy use
<br />
<br />
#include "stdafx.h"<br />
#include windows.h<br />
#include iostream<br />
#include tchar.h<br />
using namespace std;<br />
<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
char *ID;<br />
char temp = 'c';<br />
int abc = 1240;<br />
ID = new char[sizeof(ID)];<br />
<br />
wsprintf(ID,"%c%d",temp,abc);<br />
<br />
cout<<"Value="<<ID<<"\n";<br />
return 0;<br />
}<br />
<br />
<br />
whitesky
|
|
|
|
|
i dont quite understand
my objective is actually to store the lettle "C" and an int into a string so the coutcome will become like this C10 or C203
curretly the include i am using are
#include"iostream.h"
#include"string.h"
#include"iomanip.h"
i not allowed to use namespace std haha >.<
so can anyone try help me ?
|
|
|
|
|
Instead of strcat() in my first answer , use the memcpy().
I tested this code and it's working:
char *ID , Buffer[20];
int abc = 10;
int nLen = 0;
_itoa( abc , Buffer , 10 );
nLen = strlen(Buffer);
ID = new char[nLen + 2];
ID[0] = 'c';
memcpy(ID + 1 , Buffer , strlen(Buffer));
ID[nLen + 1] = '\0';
Eli
|
|
|
|
|
i tryed it with include"iostream" it works but it dosnt work in include"iostream.h"
do i have to include nay additional stuff??
by the way i say thx to all those who have helped me in advance =)
really help a lot
|
|
|
|
|
this code==> _itoa( abc , Buffer , 10 );
i tryed it with include"iostream" it works but it dosnt work in include"iostream.h"
do i have to include nay additional stuff??
by the way i say thx to all those who have helped me in advance =)
really help a lot
|
|
|
|
|
I think your problem is solve.
Can you explain what do you need exactly,please?
whitesky
|
|
|
|
|
yes my problme is solve but i cant use this function -->_itoa( abc , Buffer , 10 );
the itoa part dosnt work unless i use include"iostream" but i am using include"iostream.h"
so i am just asking there is anything else to include so that i may use include"iostream.h"
together with the itoa function
|
|
|
|
|
neodeaths wrote: so i am just asking there is anything else to include so that i may use include"iostream.h"
together with the itoa function
Yes, the prototype of the _itoa function is present in the stdlib.h header file
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
I rated you 1 -- it would be quicker for you to check MSDN library than to ask on CodeProject what itoa does.
|
|
|
|
|
>.< when i thinking i forgot got the library >.<
=P
any way thx for all the help u guys gav me
|
|
|
|
|
want to check if a folder exists in a computer or not. for example if the path is
"c:\DK\Index " i want to check if the folders DK and Index already exists in c
drive. if it doesn't exist,then these folders should be created. if the folders already exists nothing needs to be done. i want to check this when the dialog box is initialised. can anyone give the code to do this.
Thank You
|
|
|
|
|
|
Hi ,
Try this :
CFileFind finder;
CString szPath , szCMD;
szPath = "c:\DK\Index";
if(!finder.FindFile(szPath))
{
szCMD = "mkdir ";
szCMD += szPath;
system((LPCTSTR)szCMD);
}
With best regards,
Eli
|
|
|
|
|
Thank you Mr. eli the code given by you is working fine. Thanks to all of you who have responded
|
|
|
|
|
<br />
WIN32_FIND_DATA m_data;<br />
HANDLE hFile;<br />
hFile=FindFirstFile("c:\\test",&m_data);<br />
if(hFile==INVALID_HANDLE_VALUE) <br />
MessageBox("Not Found");<br />
else<br />
{<br />
MessageBox("ok");<br />
FindClose(hFile);<br />
}<br />
<br />
whitesky
|
|
|
|
|
Another way to do it: Using CFileStatus from MFC..
CString folderPath = _T("C:\\DK\\Index");
CFileStatus status;
if(!CFile::GetStatus( folderPath, status ) )
{
AfxMessageBox(_T("Directory does not exist.(\"") + folderPath + _T("\")\n"),
MB_OK|MB_ICONINFORMATION);
...
}
The use of _access (posted by Chris Losinger) may be more suitable for your needs.
-- Ricky Marek (AKA: rbid)
-- "Things are only impossible until they are not" --- Jean-Luc Picard
My articles
|
|
|
|
|
Hi !!!
If you want xou can use the InetSTL from STLSoft library. There is a function that can check wheather the directory exists or not.
You can find it here: http://www.stlsoft.org
I hope, I helped you.
By.
-:KNOX:-
|
|
|
|
|
I will really, really appreciate comments about a discussion in another web site. The reason I am asking here is because I feel unable to get an objective answer in the other site.
See the CodeGuru Forums - struct vs class? thread. I posted a message saying that the question did not ask about C structures. I will appreciate knowing if my comment is valid.
-- modified at 23:48 Saturday 20th May, 2006
|
|
|
|
|
Sam Hobbs wrote: The reason I am asking here is because I feel unable to get an objective answer in the other site.
I read through the posts but I'm not sure what your question was. You stated a "matter of factly" thing. Case closed.
The other participants seem preoccupied with quoting their textbooks. The question was too vague to begin with and warrants the issuer open a few books him/her self.
|
|
|
|
|
Thank you. Yes, I was vague intentionally. I wanted to be fair and not influence people's reaction.
|
|
|
|
|
I meant the original question that was posted by the thread initiator was vague (Sorry about any confusion). Your comment seemed appropriate based on where the thread was heading vs. what was asked.
Concerning your thread here, I wasn't sure what "objective answer" you were searching for but for what it was worth, you seemed to be stating facts and staying well within the boundaries of correctness.
|
|
|
|
|
Thank you. I sure feel good about getting support and such. I certainly felt that I was being reasonable.
I must insist however that my original question here is vague and I intended it to be.
So what I can do is if I were try to explain to anyone that there is a problem with the attitude of people in the CodeGuru forums and if someone were to try to defend the moderator person there then I can say that people in a more independent forum have expressed a different opinion. I hope it is reasonable for me to do that. It is my intent to do that in a mature, reasonable and productive manner.
-- modified at 23:06 Sunday 21st May, 2006
|
|
|
|
|
because the original-poster asked a question comparing struct+class, I would also limit my response to issues regarding C++ only - so you were right to state this.
The other posters were just trying to be helpful I think, unfortunately they were fairly inaccurate in their description of the C vs C++ issues regarding structs, especially 'andreas' who stated:
"As you can see they are different. That's because in C you are NOT defining a new data type with the definition of a structure. Therefore you need to add the keyword 'struct' in front of the name of the structure when you declare variables of it....In C++, however, a new type is defined when a structure is defined, and you can use this new type to declare variables, and the struct keyword is NOT needed."
this is incorrect, in both C and C++ you are defining a new type "struct name", and it must always be referred to as this. However C++ contains a bodge, and whenever you define a struct in this language it also installs an alias to that struct-type sharing the same name:
In C++ when you do this:
struct mystruct
{
};
It is really doing this (from a C point of view)
struct mystruct
{
};
typedef struct mystruct mystruct;
http://www.catch22.net
|
|
|
|