|
Hi,
I have an private mem as char* author_name[30];
If I want to take input from user then How should I use this in cin>> syntax?
Error:
I m using cin>>author_name[30];
It shows an unexceptional error occur.
Rupali Sarda
|
|
|
|
|
You get an exception because you declared a pointer to a pointer, it's like declaring char** .
You have no memory allocated for that pointer so cin>> will atempt to write in some random memory location.
|
|
|
|
|
To complete previous response, it will work if you remove the *:
char author_name[30];
And then:
cin>>author_name;
|
|
|
|
|
As it is a private member, u cant use like this cin>>author_name.because private member r accesible throug h their member function ,friend function,friend class.
better u create char pointer say
char input_user[30];
cin>>input_user;
say the private member is defined in a class
Class AUTHOR_NAME
{
public:
author_name(char name) //constructor
{strcpy(author_name,name);}
private: char author_name[30];//private member
};
-- modified at 2:13 Friday 23rd September, 2005
|
|
|
|
|
Rupali sarda wrote:
have an private mem as char* author_name[30];
here is small program for you.....
void main()
{
char *name[30];
for(int i=0;i<2;i++)
{
name[i]=new char[30];
cin>>name[i];
}
for(i=0;i<2;i++)
{
cout<<name[i];
delete [] name[i];
}
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
welcome simple but nice one !
V
|
|
|
|
|
Hi,
In my application i've few edit boxes ,the value in them can be edited by the user during runtime.i've set a limit for the number of integers they can enter and after the user enters the value i want to trap them in a SINGLE CLICK message handler.I dont want to use EN_CHANGE handlerfor this.will it be possible for me to do it this way?
thank you in advance.
rajeev
|
|
|
|
|
A way to do that is to derive a class from CEdit and in that class trap the WM_LBUTTONDOWN message. From the WM_LBUTTONDOWN handler notify the parent about the event and that's it. The edit boxes from your application have to be instances of your derived class.
|
|
|
|
|
Dear all,
I have created a process and wait for it to complete a certain job. e.g. "Driver Installation".
When the driver installs, it will request the user to re-start (or skip) your PC. If you choose not to re-start your PC; the main process will continue the incomplete job. On the contrary, if you choose to re-start the PC, the system will cause “Circular Wait”. Because the process informs main process whether the session is ending. In this case- how should I know if the process shows that I need to re-start the computer? If the main process has received the reboot message and then just go to leave.
SHELLEXECUTEINFO ExecuteInfoDriver;
memset(&ExecuteInfoDriver, 0, sizeof(ExecuteInfoDriver));
LPCTSTR lpctDriverPath = (LPCTSTR)DriverPath;
ExecuteInfoDriver.cbSize = sizeof(ExecuteInfoDriver);
ExecuteInfoDriver.fMask = SEE_MASK_NOCLOSEPROCESS;
ExecuteInfoDriver.hwnd = 0;
ExecuteInfoDriver.lpVerb = "open";
ExecuteInfoDriver.lpFile = lpctDriverPath;
ExecuteInfoDriver.lpParameters = NULL;
ExecuteInfoDriver.lpDirectory = 0;
ExecuteInfoDriver.nShow = SW_SHOW;
ExecuteInfoDriver.hInstApp = 0;
......
if (::ShellExecuteEx(&ExecuteInfoDriver))
{
hDriverProcess = ExecuteInfoDriver.hProcess;
if (hDriverProcess != NULL)
{
::WaitForSingleObject(hDriverProcess, INFINITE);
::CloseHandle(hDriverProcess);
}
}
....
do something...
....
Thanks for your help, I really appreciate it.
Best Regards
Steve Chang.
|
|
|
|
|
Hi ,
I was trying to compile a DirectShow sample called the MultiVMR9 from the DirectShow SDK samples,
and I'm getting the following compile error message. Does anyknow how to get around this? or what I'm doing wrong here ?
I'm using VS.NET 2003
Thanks in advance.
g:\Program Files\Microsoft Platform SDK\Samples\Multimedia\DirectShow\Samples\C++\DirectShow\VMR9\MultiVMR9\MultiPlayer\VMR9Subgraph.cpp(78): error C2065: 'CLSID_VideoMixingRenderer9' : undeclared identifier
g:\Program Files\Microsoft Platform SDK\Samples\Multimedia\DirectShow\Samples\C++\DirectShow\VMR9\MultiVMR9\MultiPlayer\MultiPlayer.cpp(55): error C2065: 'CLSID_VideoMixingRenderer9' : undeclared identifier
-Cindy
|
|
|
|
|
the Operation System is Win NT/XP
i want to write a print preview and setup program, i've fount in msdn library,
I get the DEVMODE structure,and modify the dmFormName Field to my own FormName(which have been use AddForm() to insert into to system),but why my program cant work out ,can anybody give me some tips?
|
|
|
|
|
Hello, i need help in my project based on content based image retrieval system where i will have to extract shape from sketches submitted by the user n compare it to other images...i am actually searching for code in VC++ for shape matching(fourier,grid-based descriptor,etc) n also code to detect geometric shape like circle,triangle,ect...plz help me..thx u in advance
Yesha
|
|
|
|
|
hello
what do I do if I want to print a string like this:
("how")
with fprintf
because if I do this fprintf(stream,"("how")");
it gives me compiler errors??
|
|
|
|
|
In C/C++, the backslash \ is the escape. So, you'd do this:
fprintf(stream, "(\"how\")");
|
|
|
|
|
How would i write a trim(char *str) function??
|
|
|
|
|
run through the string from the start, find the first non-whitespace. run through it from the end, find the last whitespace. the result is everything between those two points.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
|
example:
output:
Enter a sentence and I will strip out all spaces.
this is a test of the emergency broadcast system
Your sentence without spaces (8) is:
this.is.a.test.of.the.emergency.broadcast.system
code:
int stripWhite(char *str)
{
int len=0; // number of spaces
char *ptr = str;
int pos = 0;
while(*ptr)
{
if (isspace(*ptr))
{
len++;
*ptr = '.';
}
ptr++; pos++;
}
return len;
}
so i want to take all spaces out of a string instead of what i do now (replace with '.' so the string is:
thisisatestoftheemergencybroadcastsystem
how?
|
|
|
|
|
use ::strcpy to copy the rest of the string from that position down one. Make sure you copy the null at the end as well.
Christian Graus - Microsoft MVP - C++
-- modified at 23:21 Thursday 22nd September, 2005
Here's a solution:
#include "stdafx.h"
#include <iostream>
using namespace std;
size_t trim(char * str)
{
size_t len = ::strlen(str);
for(size_t i =0; i < len; ++i)
{
if (::isspace(str[i]))
{
::strcpy(&str[i], &str[i+1]);
-- len;
}
}
return len;
}
int _tmain(int argc, _TCHAR* argv[])
{
char * str1 = new char[200];
strcpy(str1, " This is a test of the veracity of my system..... ");
cout << strlen(str1);
cout << trim(str1);
cout << str1;
cin >> str1;
return 0;
}
|
|
|
|
|
Christian Graus wrote:
::strcpy(&str[i], &str[i+1]);
That will probably work, but depends on the compiler implementation. From the remarks on strcpy documentation[^]:
"The behavior of strcpy is undefined if the source and destination strings overlap."
Here's an alternative, which doesn't use strcpy , and in which each character is copied only once. How and why this works is left as an exercise to the original poster.
size_t strip_white(_TCHAR* str)
{
_TCHAR* p = str;
_TCHAR* q = str;
while (*q)
{
if (::_istspace(*q))
q++;
else
{
if (p != q)
*p = *q;
p++; q++;
}
}
*p = '\0';
return p - str;
}
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
I started with something like this, then decided it was bloat, easily replaced by strcpy. I guess I should have looked a little closer. Is memcpy the same ?
|
|
|
|
|
Christian Graus wrote:
I started with something like this, then decided it was bloat, easily replaced by strcpy. I guess I should have looked a little closer. Is memcpy the same ?
Yes, memcpy is also undefined for overlapping buffers. You could use memmove , though, which does support overlaps.
However, an additional problem in that solution is one of efficiency. Since for each space found you copy the remainder string, many characters are copied multiple times. In you example, which used " This is a test of the veracity of my system..... " as input, which is a short 50 bytes string, the following substrings were copied:
"This is a test of the veracity of my system..... " = 49 bytes
"is a test of the veracity of my system..... " = 44 bytes
"a test of the veracity of my system..... " = 41 bytes
"test of the veracity of my system..... " = 39 bytes
"of the veracity of my system..... " = 34 bytes
"the veracity of my system..... " = 31 bytes
"veracity of my system..... " = 27 bytes
"of my system..... " = 18 bytes
"my system..... " = 15 bytes
"system..... " = 12 bytes
In total, 310 characters were copied. In the alternative solution, each character of the final result was copied only once, that is, only 39 single-byte copy operations were performed. 310 is almost 8 times 39, and to make things worse, the proportion will grow exponentially for larger strings. For example, if we used as input the same string concatenated to the original one (a 100 bytes string), one algorithm would perform 78 byte copy operations, while the other would do 1120, which is more than 14 times larger. If we used as input three times the original string (150 bytes), the numbers would then be 117 bytes copied in one algorithm against 2430 in the other, which is more than 20 times larger!
Using while (*q) instead of the strlen + for combination is an additional optimization, because you don't need to traverse the whole [potentially long] string just to find out its length. Using while , all the processing can be done in a single pass.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Hi guys ,
i have next question :
what will the output be of this program?
...
char* foo()
{
char *c = "this is a test";
return c;
}
char* foo1()
{
char c[] = "this is a test";
return c;
}
int _tmain(int argc, _TCHAR* argv[])
{
...
char p1 = foo1();
char p = foo();
cout<<p1<<endl;
cout<<p;
return 0;
...
}
i dont get it. i thought that the output of foo() and foo1() had to be the same . more exactly foo1() had to print some strange symbols as the memory allocated for c[] would be freed after this funcion ended. but why does not the sane happen with c* in foo()?
what am i getting wrong??
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
-- modified at 17:48 Thursday 22nd September, 2005
|
|
|
|
|
Giorgi Moniava wrote:
char c[] = "this is a test";
Because it's an array, this memory is allocated in to context of the function, and lost when you return.
Giorgi Moniava wrote:
char *c = "this is a test";
Because it's a pointer, this memory is not freed, and so is a leak, unless the caller deletes it.
In both cases, you'd do better to return std::string. ( Yes, I realise this is an experiment, but that's the lesson to learn from it )
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
Because it's a pointer, this memory is not freed, and so is a leak, unless the caller deletes it.
Nom you don't have to (and you shouldn't) delete this memory, otherwise you will get an assertion. This memory has not been dynamically allocated so it shouldn't be deleted by the user. The two cases are the same. No memory has been dynamically allocated so everything will be freed at the end of the function.
Christian Graus wrote:
In both cases, you'd do better to return std::string
So true
|
|
|
|