|
You're welcome.
|
|
|
|
|
hi i need help with reading data with my fscanf function
i have been reading some tutorial and they say that when i do fscanf(pfile,"%s",string)
the string will stop reading once it reads a white space
however my txt file is like name 1,dob,date
as you can see its seperated by an comman(,) and there white spaces inbetween the names sometimes
does anyone got any idea how to deal with this problem? please tell me and giv suggestions pls
|
|
|
|
|
do u have already tried fgets?
|
|
|
|
|
the function seems to store the whole file into an string though
|
|
|
|
|
the function seems to store the whole file into an string though..
if i do that i cant store my values into different variables
|
|
|
|
|
IMHO you have to read the file line by line and parse every line read.
To parse the read line you may use:
(1) hand crafted line parser.
(2) a string class (as std::string).
(3) a Regex parser (as Expresso).
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.
[my articles]
|
|
|
|
|
neodeaths wrote: does anyone got any idea how to deal with this problem?
Yes, try:
int a;
char dob[16];
char date[16];
fscanf("%d,%s,%s", &a, b, c); Note the types used and their size are highly dependent on the format of the file. You should seek other solutions.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi friends,
We are invoking a window which containe the grid, in grid we have combo box ( Which is drop down list style). We are able get the handle of grid( we are unable to get the handle or object id combo box).
My question is,
1) IS it possible to get the data from that combo box using grid handle??
2) Is there any method to get the data from that combo box??
Please help me..........
please help me is it possible or not??
---------------FYI-----------------------------------
1) I tried CCombbox class
2) I am using VC++ 6.0 version
thanks
Anand
Anand
modified on Thursday, December 27, 2007 2:19:36 AM
|
|
|
|
|
Hi friends,
We are invoking a window which containe the grid, in grid we have combo box ( Which is drop down list style). We are able get the handle of grid( we are unable to get the handle or object id combo box).
My question is,
1) IS it possible to get the data from that combo box grid handle??
2) Is there any method to get the data from that combo box??
Please help me..........
I am trying last one month back, i am unableto resolve this issue.
please help me is it possible or not??
thanks
Anand
|
|
|
|
|
Hi All,
I have some Spin control - and i want to increment or decrement the value in my edit box in 0.1 in each spin step.
I try to look in the MSDN and i see that each increment or decrement of the a value is in integer value step.
How can i increment or decrement in 0.1 in each step ?
( I mean that if i have in the Edit box the value 5 and i press on increment arrow that i need to have the value 5.1 in the edit box )
Thanks for the help.
|
|
|
|
|
Yanshof wrote: I try to look in the MSDN and i see that each increment or decrement of the a value is in integer value step.
this is a workaround not a actual programming!, you just have to a variable which contain the current value in edit control and you have to handle the EN_CHANGE message of edit control. i.e. when ever the value of edit box change due to spinctrl, you update the value in edit control accordingly!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
Hello everyone,
In GotW #66, one of the moral is the exception handler of constructor should not do any like resource free task. I do not agree. Here is the quoated moral and my code to prove this moral will have memory leak.
Anything wrong with my analysis?
http://www.gotw.ca/gotw/066.htm
Moral #1: Constructor function-try-block handlers have only one purpose -- to translate an exception. (And maybe to do logging or some other side effects.) They are not useful for any other purpose.
class A
{
private:
int* p;
public:
A()
try
{
p = new int[10];
}
catch (bad_alloc)
{
}
catch (...)
{
if (p) delete[] p;
}
}
thanks in advance,
George
|
|
|
|
|
He also continues to say that
- resources should be allocated in the body (rather than the initializer list)
- failed allocation of these resources should be handled by a "normal", not a function exception block.
The point is that for the scenario discussed - base class or member constructors failing - THERE IS NO INSTANCE OF A, and following from that there is no p that you could test.
|
|
|
|
|
Thanks peterchen,
I agree that there is no instance of A. But there exists memory allocated and pointed by pointer p, right? We need to free it if it is allocated successfully (in my case, there is no bad_alloc exception, which indicates the memory is allocated and we must free -- there is some other exception afterwards)
p = new int[10];
regards,
George
|
|
|
|
|
No, becaue the exception you are catching is thrown before that allocation is executed.
|
|
|
|
|
Sorry peterchen,
I may not make myself fully understood. I mean we allocate memory on heap successfully, using
int* p = new int[10];
then there is another exception thrown after we successfully allocate the memory. In this case, it is leaked, right (so RAII model does not work in this case)?
regards,
George
|
|
|
|
|
Hi George,
You are nto giving up - that's good
I overlooked the comment for extra code that might throw exceptions.
With that code, you got yourself in a very ugly situation:
If you catch the (...) exception, where was it thrown? by a base class, or a member constructor? IUn that case, you cannot even legally test p!=0 (it is likely randomly initialized, anyway, and the compiler might generate code that causes an access violation at runtime).
What you need to do is this:
class A
{
private:
int* p;
public:
A() try
{
try
{
p = NULL;
p = new int[10];
}
catch (...)
{
}
}
catch (...)
{
}
}
|
|
|
|
|
Hi peterchen,
To answer your questions,
1. where are the exceptions from? Two sources, bad_alloc from new and some other places after we successfully allocated memory for p.
Here is my code,
// ... there are some other exceptions here
peterchen wrote: If you catch the (...) exception, where was it thrown?
2. about value of p
If new is successful, surely we can use !p to check whether it is ok to free memory. If it is bad_alloc exception, I will never delete it.
peterchen wrote: IUn that case, you cannot even legally test p!=0 (it is likely randomly initialized, anyway, and the compiler might generate code that causes an access violation at runtime).
If there is anything wrong in my code, please feel free to correct me.
regards,
George
|
|
|
|
|
Re-read the GotW article again. Your issues are addressed in it.
Specifically,
'"...to free resources allocated in the initializer list or in the constructor body!"
Sorry, nope. After all, remember that once you get into your constructor try-block's handler, any local variables in the constructor body are also already out of scope, and you are guaranteed that no base subobjects or member objects exist any more, period. You can't even refer to their names.'
This means p may not be referenced in the exception handler. The object does not exist. The object members do not exist.
|
|
|
|
|
Hi Member 754960,
I will delete p in the local try block handler and re-throw the exception, other than function try block handler. Do you think this way is ok?
regards,
George
|
|
|
|
|
Rethrowing the exception is fine.
Trying to delete p would be an error.
You cannot address p.
It doesn't exist.
Forget it, it's lost.
So is the memory allocated to initialize it.
So, don't do it this way.
Do what the article recommends: Use a container object.
|
|
|
|
|
No Member 754960,
We can access in local function try block, but not in function try block -- they are two different things.
Here is the guideline from GotW
http://www.gotw.ca/gotw/066.htm[^]
--------------------
Moral #4: Always clean up unmanaged resource acquisition in local try-block handlers within the constructor or destructor body, never in constructor or destructor function-try-block handlers.
--------------------
If you have any issues, please feel free to let me know.
regards,
George
|
|
|
|
|
The original question was in reference to the function try-catch handler.
If you want to use a local try catch block in the ctor body, as the GotW indicates, to handle the unmanaged memory, fine.
|
|
|
|
|
Thanks Member 754960,
I agree. Cool.
regards,
George
|
|
|
|
|
I try to convert my old MFC application that use multibye encoding to UNICODE by using TCHAR programming method.
but there is a code the create a file using ofstream that I dont know how to convert to TCHAR-programming.
I also tried std::wofstream
<br />
wofstream outFile(_T("outfile.txt"));<br />
outFile<<_T("Test international character : ???????,??????\n");<br />
outFile.close();<br />
But it didn't work , only the english portion is written to the output file (and the file are still ASCII as open in notepad).
Can someone suggest me how to fix the problem ?
Another question what is length in function like GetWindowText and GetCurrentDirectory are.Is it number of character or a number of byte ?
Edit : those ?????? are suppose to be thai and arabic text
|
|
|
|