|
Hi Mukesh, Thanks for the reply.
ctually I want to access it by code i.e. programmatically accessing the call stack. Sorry for the confusion.
Regards,
Mushq
|
|
|
|
|
What do you mean ? Do you want to access it by code ? Or just look at it yourself ? If it is the latter, it depends of which IDE you are using. For VS2005, you go into 'Debug' -> 'Windows' -> 'Call Stack'. You have of course to start debugging. The call stack will be displayed whenver you hit a breakpoint.
|
|
|
|
|
Thanks for reply.
Cedric Moonen wrote: What do you mean ? Do you want to access it by code ? Or just look at it yourself ?
Actually I want to access it by code i.e. programmatically accessing the call stack. Sorry for the confusion.
Regards,
Mushq
|
|
|
|
|
|
I need to add " to a string both at the beging and ending of the string and make the string looking like
"test string"
" should also part of the string... pls advice
|
|
|
|
|
You need to add an escape character ('\' before the character). It will look like this: \"test string\".
|
|
|
|
|
char ch ='\"';
lgAssistantLocStr = ch + LocStr + ch;
I am getting expected string but it is not working as excepted.... is that due to some interal problems...pls advice
|
|
|
|
|
ptr_Electron wrote: but it is not working as excepted
Which means what ??
ptr_Electron wrote: char ch ='\"';
lgAssistantLocStr = ch + LocStr + ch;
You can't concatenate char pointers like that. What is the type of lgAssistantLocStr and of LocStr ?
|
|
|
|
|
it is string...
string lgAssistantLocStr;
|
|
|
|
|
And what about the first question I asked ?
Anyway, you can't add a std::string to a character because a character doesn't have an overloaded operator +.
Do something like that:
std::string strTemp = "\"";<br />
lgAssistantLocStr = strTemp + YourString + strTemp;
|
|
|
|
|
ptr_Electron wrote: I am getting expected string but it is not working as excepted....
What do you mean?
How is lgAssistantLocStr defined?
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
|
|
|
|
|
it is a string
string lgAssistantLocStr;
|
|
|
|
|
OK, but what is the expected behaviour and what is the problem you're complaing about?
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
|
|
|
|
|
ptr_Electron wrote: I am getting expected string but it is not working as excepted...
This makes no sense.
"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
|
|
|
|
|
When i execute the code given below in C on Visual Studio 2008 i get the following error messages
1>------ Build started: Project: socketclientc, Configuration: Debug Win32 ------
1>Compiling...
1>client.c
1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(872) : see declaration of 'WSACleanup'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(69) : error C2059: syntax error : 'return'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(70) : error C2059: syntax error : '}'
1>Build log was saved at "file://c:\Documents and Settings\HP\My Documents\Visual Studio 2008\Projects\socketclientc\socketclientc\Debug\BuildLog.htm"
1>socketclientc - 25 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
// practiceclient.c : Defines the entry point for the console application.
#include <stdio.h>
#include <winsock2.h>
int main()
{
WSADATA wsadata;
WORD wVersion;
int wsaerr;
wVersion = MAKEWORD(2,2);
wsaerr = WSAStartup(wVersion, &wsadata);
if(wsaerr != 0)
{
printf("There is a DLL linker problem");
return 0 ;
}
else
printf("\nDLL working and compatible!!");
SOCKET mysocket;
mysocket = socket(AF_INET,SOCK_STREAM,0);
if(mysocket == SOCKET_ERROR)
{
printf("socket cannote be created error: %d",WSAGetLastError);
WSACleanup();
return 0;
}
printf("\nSocket created successfully");
sockaddr_in Cservice;
Cservice.sin_family = AF_INET;
Cservice.sin_addr.s_addr = inet_addr("127.0.0.1");
Cservice.sin_port = htons(55555);
if(connect(mysocket,(sockaddr *)&Cservice,sizeof(Cservice))== SOCKET_ERROR)
{
printf("Connect is unsuccessful, error:%d",WSAGetLastError);
WSACleanup();
getchar();
return 0;
}
int bytesent;
int byterecv=SOCKET_ERROR;
char sendbuff[200] = "Client:This is a test string from client.";
char recvbuff[200] = "";
while(byterecv == SOCKET_ERROR)
{
byterecv = recv(mysocket,recvbuff,strlen(recvbuff),0);
if(byterecv==0||byterecv==WSAECONNRESET)
printf("\nClient: Connection closed");
if(byterecv>0)
return 0;
else
{
printf("\nClient: recv() is OK");
printf("\nClient: The string received %s",recvbuff);
printf("\nClient: The bytes received %d",byterecv);
}
}
bytesent=send(mysocket,sendbuff,strlen(sendbuff),0);
if(bytesent == SOCKET_ERROR)
printf("\nClient: send() failed:%d",WSAGetLastError);
else
{
printf("\n Client: send() is OK");
printf("\n Client: The string sent %s",sendbuff);
printf("\n Client: The number of bytes sent %d",bytesent);
}
getchar();
WSACleanup();
return 0;
}
|
|
|
|
|
Please check the posting guidelines before posting a message. Put your code inside code or pre tags and replace the < and > characters so that they can be visible. Furthermore, you selected only a part of the errors and you took the less relevant ones
Did you include winsock2.h ?
|
|
|
|
|
yea i used winsock2.h
and this program executes without problem in C++ but when i save the file as .c extension adn then i get so many errors do you want me to post my code again.
i need serrious help here
|
|
|
|
|
I would like to see which files you include and the complete errors that you have.
|
|
|
|
|
Thank you for reminding me to do that. Thanks a million i got it working all over again.
|
|
|
|
|
If you save the file with a .c extension, when then try to compile it, it will compile as a C file and not C++. So if you use any C++-specific constructs (which your code does), it will fail to compile.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Hi,
In C you are required to declare the variables at the beginning of the block. but this is not necessary in C++. In C++ u can declare the variable just before it is going to be used . But this will show as erorr in C. so in your code the following bold statements cause errors in C.
#include
#include
int main()
{
WSADATA wsadata;
WORD wVersion;
int wsaerr;
wVersion = MAKEWORD(2,2);
wsaerr = WSAStartup(wVersion, &wsadata);
if(wsaerr != 0)
{
printf("There is a DLL linker problem");
return 0 ;
}
else
printf("\nDLL working and compatible!!");
SOCKET mysocket;
mysocket = socket(AF_INET,SOCK_STREAM,0);
if(mysocket == SOCKET_ERROR)
{
printf("socket cannote be created error: %d",WSAGetLastError);
WSACleanup();
return 0;
}
printf("\nSocket created successfully");
sockaddr_in Cservice;
Cservice.sin_family = AF_INET;
Cservice.sin_addr.s_addr = inet_addr("127.0.0.1");
Cservice.sin_port = htons(55555);
if(connect(mysocket,(sockaddr *)&Cservice,sizeof(Cservice))== SOCKET_ERROR)
{
printf("Connect is unsuccessful, error:%d",WSAGetLastError);
WSACleanup();
getchar();
return 0;
}
int bytesent;
int byterecv=SOCKET_ERROR;
char sendbuff[200] = "Client:This is a test string from client.";
char recvbuff[200] = "";
while(byterecv == SOCKET_ERROR)
{
byterecv = recv(mysocket,recvbuff,strlen(recvbuff),0);
if(byterecv==0||byterecv==WSAECONNRESET)
printf("\nClient: Connection closed");
if(byterecv>0)
return 0;
else
{
printf("\nClient: recv() is OK");
printf("\nClient: The string received %s",recvbuff);
printf("\nClient: The bytes received %d",byterecv);
}
}
bytesent=send(mysocket,sendbuff,strlen(sendbuff),0);
if(bytesent == SOCKET_ERROR)
printf("\nClient: send() failed:%d",WSAGetLastError);
else
{
printf("\n Client: send() is OK");
printf("\n Client: The string sent %s",sendbuff);
printf("\n Client: The number of bytes sent %d",bytesent);
}
getchar();
WSACleanup();
return 0;
}
thanks
Nitheesh
|
|
|
|
|
Yea thanks for tht but even after taking the variable declarations in the begining of the program i get error messages. For socket programming does C have some other constructs? Cos the books i used had socket as a structures and i could use it. can anyone suggest anything?
cheers
this is the error messages that i get.
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(11) : error C2065: 'sockaddr_in' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(11) : error C2146: syntax error : missing ';' before identifier 'Cservice'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(11) : error C2065: 'Cservice' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(12) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(13) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(14) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(15) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(33) : error C2065: 'Cservice' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(33) : error C2224: left of '.sin_family' must have struct/union type
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(34) : error C2065: 'Cservice' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(34) : error C2224: left of '.sin_addr' must have struct/union type
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(35) : error C2065: 'Cservice' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(35) : error C2224: left of '.sin_port' must have struct/union type
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(36) : error C2065: 'sockaddr' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(36) : error C2059: syntax error : ')'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(44) : error C2059: syntax error : 'while'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : error C2065: 'mysocket' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : error C2065: 'sendbuff' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : warning C4024: 'send' : different types for formal and actual parameter 2
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : error C2065: 'sendbuff' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : warning C4024: 'strlen' : different types for formal and actual parameter 1
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : error C2099: initializer is not a constant
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(59) : error C2059: syntax error : 'if'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(61) : error C2059: syntax error : 'else'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(68) : warning C4273: 'getchar' : inconsistent dll linkage
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(273) : see previous definition of 'getchar'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(69) : error C2373: 'WSACleanup' : redefinition; different type modifiers
1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2161) : see declaration of 'WSACleanup'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(70) : error C2059: syntax error : 'return'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(71) : error C2059: syntax error : '}'
1>Build log was saved at "file://c:\Documents and Settings\HP\My Documents\Visual Studio 2008\Projects\socketclientc\socketclientc\Debug\BuildLog.htm"
1>socketclientc - 25 error(s), 5 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
|
|
|
|
Thank you for reminding and helping me out i got it all working now.
|
|
|
|
|
Hello Guru's
I am making a application in MFC ( Modal Dialog Based ) But its form size is constant as we have fixed at design time . Can any one told me how can make it Maximized automatic after clicking maximized box.
Regard's
Kaushik
|
|
|
|
|
Sorry, but I'm not sure I understood your problem correctly. Do you want that the controls on your dialog position themselves correctly when you maximize your dialog ?
If that's the case, then take a look at these articles[^]. The first one looks promising.
If it's not what you asked for, then explain your problem more clearly.
|
|
|
|