|
try this
float x = 2.1;
int n= x;
if( n < x )
{
n++;
x = n;// x will contain 3 now
}
nave
|
|
|
|
|
thanks for that.
how do i print a double value? i mean the type specifier?
|
|
|
|
|
|
Hi all . could any one show me how to use [B]Microsoft HTML Object Library [/B] in visual c++ 6 to extract data from html and populate it in listview. I have done this in visual basic 6 and i posted the code below . I be happy if an expert help me convert it to visual c++ 6 since i need it for a project that has to be done in visual c++ 6. My current visual c++ code retrives html of url and all now i need to be able to do extract the data i wanted from html and populate the listview with that data. I shown a picture of output in the pic.Thanks
code that retrives the html for me in visual c++ 6:
<br />
void CFindUserDlg::OnButton4() <br />
{<br />
<br />
HINTERNET hNet = ::InternetOpen("MSDN SurfBear",PRE_CONFIG_INTERNET_ACCESS,NULL,INTERNET_INVALID_PORT_NUMBER,0) ;<br />
HINTERNET hUrlFile = ::InternetOpenUrl(hNet,"http://www.mysite.com/Display.php",NULL,0,INTERNET_FLAG_RELOAD,0) ;<br />
<br />
char buffer[10*1024] ;<br />
<br />
DWORD dwBytesRead = 0;<br />
BOOL bRead = ::InternetReadFile(hUrlFile,buffer,sizeof(buffer),&dwBytesRead);<br />
<br />
SetDlgItemText(IDC_EDIT2,buffer);<br />
<br />
::InternetCloseHandle(hUrlFile) ;<br />
::InternetCloseHandle(hNet) ;<br />
<br />
<br />
<br />
}
visual basic 6 code:
<br />
<br />
Private Sub Command3_Click()<br />
'this function places data into listview<br />
' requires that you add a reference to the Microsoft HTML Object Library<br />
Dim mydoc As HTMLDocument<br />
Dim wombat As IHTMLElementCollection<br />
Dim lp As Long<br />
<br />
Set mydoc = New HTMLDocument<br />
<br />
'mydoc.body.innerHTML = "<html><head><p><ul><table border=1 cellpadding=4> " & _<br />
' "<tr><th>Name</th> > <th> color </th> </tr> " & _<br />
' "<tr><td>tony</td> <td>33023</td> " & _<br />
' "<tr><td>cindy</td> <td>16711935</td> " & _<br />
' "<tr><td>sarah</td> <td>3434343</td> " & _<br />
' "</table> </body></html>"<br />
<br />
mydoc.body.innerHTML = RichTextBox1.Text<br />
<br />
Set wombat = mydoc.getElementsByTagName("TR") ' Get the rows<br />
For lp = 1 To wombat.length - 1 ' Ignore first row<br />
Set LI = ListView1.ListItems.Add(lp, , wombat.Item(lp).All.Item(0).innerText)<br />
ListView1.ListItems(lp).ForeColor = wombat.Item(lp).All.Item(1).innerText<br />
LI.ListSubItems.Add , , wombat.Item(lp).All.Item(1).innerText<br />
<br />
Next<br />
End Sub
picuture of the output:
[IMG]http://i5.photobucket.com/albums/y180/method007/ListViewPop.jpg[/IMG]
|
|
|
|
|
Why dont you use Regular Expression to extract data?
|
|
|
|
|
well i do not know how to use it . could u show me how to extract it using either method and populate the listview.thanks
|
|
|
|
|
The following program doesn't free all the memory. Can any one tell me what is wrong with the code?
Thanks.
//
wchar_t *pwcTest = L"Test";
int g_I=1000;
void AllocateMem(wchar_t ***pwcArray)
{
*pwcArray = (wchar_t**)new wchar_t*[g_I+1];
ZeroMemory(*pwcArray, sizeof(wchar_t*)*g_I+1);
for(int i=0; i<g_I; i++) {
(*pwcArray)[i] = (wchar_t*)new wchar_t[wcslen(pwcTest)+1];
wcscpy((*pwcArray)[i], pwcTest);
}
(*pwcArray)[i] = NULL;
}
void FreeArray(wchar_t **pwcDC)
{
if(pwcDC != NULL) {
for(int i=0; pwcDC[i] != NULL; i++)
delete [] pwcDC[i];
delete [] pwcDC;
}
}
int main( int argc, char *argv[ ])
{
char s[2];
printf("main:\n");
fscanf(stdin, "%s", s);
// Mem Usage (in the Windows Task Manager): 632K
wchar_t **pwcArray = NULL;
for (int i=0; i<1000; i++) {
AllocateMem(&pwcArray);
FreeArray(pwcArray);
}
printf("main: %d\n", i);
fscanf(stdin, "%s", s);
// Mem Usage: 688K (g_I=1000)
// Mem Usage: 908K (g_I=10000)
return 0;
}
//
mdexch
|
|
|
|
|
I reformatted your code to make it easier for me to read, particularly since C++ (which you are using) provides references.
wchar_t *pwcTest = L"Test";
int g_I=1000;
void AllocateMem(wchar_t**& pwcArray)
{
pwcArray = new wchar_t*[g_I+1];
ZeroMemory(pwcArray, sizeof(wchar_t*) * (g_I+1) );
for(int i=0; i<g_I; i++) {
pwcArray[i] = new wchar_t[ wcslen(pwcTest) + 1 ];
wcscpy(pwcArray[i], pwcTest);
}
pwcArray[ g_I ] = NULL;
}
void FreeArray(wchar_t **pwcDC)
{
if(pwcDC != NULL) {
for(int i=0; pwcDC[i] != NULL; i++)
delete [] pwcDC[i];
delete [] pwcDC;
}
}
int main( int argc, char *argv[ ])
{
char s[2];
printf("main:\n");
fscanf(stdin, "%s", s);
wchar_t** pwcArray = NULL;
int i;
for (i=0; i<1000; i++) {
if (i%100 == 0)
fprintf(stdout, "%d\n", i);
AllocateMem(pwcArray);
FreeArray(pwcArray);
}
printf("main: %d\n", i);
fscanf(stdin, "%s", s);
return 0;
}
I don't believe my version leaks memory, though I only spent a couple minutes on this. The CRT will ask windows for memory then hold on to it for future requests, even if from your perspective you haven't currently allocated it -- or at least this is my understanding.
earl
PS: VS2005: beginning 960K, end 1000K, regardless i = {1000,10000,50000}
-- modified at 19:28 Wednesday 12th July, 2006
|
|
|
|
|
Look like a CRT issue. On .Net 2003 compiler I see less memory allocation but different for different array size. May be 2005 is different.
Thanks for the input.
mdexch
|
|
|
|
|
I didn't see a leak; do note that when a heap is allocated, it may not be entirely released until the CRT deinitializes. This is not a memory leak, but an optimization.
I did see a problem with your code, though:
*pwcArray = (wchar_t**)new wchar_t*[g_I+1];<br />
ZeroMemory(*pwcArray, sizeof(wchar_t*)*g_I+1);
Note that you are allocating g_I + 1. The last item is being used as a guard item. Yet when zeroing the memory, you are zeroing out 4001 bytes (when g_I is set to 1000), not 4004. You need to wrap parenthesis around g_I + 1 as follows:
ZeroMemory(*pwcArray, sizeof(wchar_t*)*(g_I+1));
I would recommend placing the wchar_t strings in a struct with a destructor and then making the array and array of these structures (or use string or CString).
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
for(int i=0; pwcDC[i] != NULL; i++)
//How can be the above expression can be valid one that
is the one which is checking "pwcDC[i] != NULL" in which
we may actually be doing ABR( Array bound read) or anything so.
I am begginer in this so can u help me in this ?.
Thanks
Pavan
|
|
|
|
|
Assume you have an array of 5 pointers, the last slot always has a NULL value and the first 4 always have valid pointers. You can then loop through the array until you find the NULL pointer.
With rare exceptions, this is a terrible programming technique. It is best to simply use the known bounds of the array or, better yet, use a collection class.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
<small>Hi,
I am reading a text file line by and line and reading the values into variables using sscanf. The problem I am having is that sscanf will return the correct value for the number of columns that I have, however, it only puts the first value into first variable and ignores the remaining variables.
This is a snippet of the text file I am reading:
</small>
<code>Y8145L 0 1 1
Y8148L 0 1 1</code>
This is the code snippet:
<code>while(fgets(pointListID, sizeof(pointListID), unit1File))
{
if(feof(unit1File))
break;
double testA;
double testB;
double testC;
char testshortPointID[8];
if((sscanf(pointListID, "%s %d %d %d",&testshortPointID, &testA, &testB, &testC))==4)
{...}</code>
testA, testB and testC values never change when I run this.
Any help is appreciated!
Sande
|
|
|
|
|
for starters, %d is an int and %e is a float.
earl
-- modified at 18:51 Wednesday 12th July, 2006
Sorry, le should be a double.
|
|
|
|
|
Thanks ever so! I tried using %e and that wouldn't work, so I changed my doubles to float and presto!
Thanks alot!
sande
|
|
|
|
|
I edited my post, but le (or lf, I think) will do doubles for you.
earl
|
|
|
|
|
Thanks, I saw that... and it works! you're fabulous!!
sande
|
|
|
|
|
If you use C++ stream classes and strings instead of old non-typesafe C functions this kind of problem isn't possible. Here's a complete example with error checking:
---------------------------------
// Console.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
int main(int argc, char *argv[])
{
using namespace std;
// Open the file.
ifstream ifs("C:\\a.txt");
if (!ifs)
{
cerr << "Failed to open input file!" << endl;
return 1;
}
// Read in line at a time.
unsigned int LineNumber = 1;
string Line;
while (getline(ifs, Line))
{
// Now break up the line.
istringstream iss(Line);
string PointID;
int x, y, z;
if (!(iss >> PointID >> x >> y >> z))
{
cerr << "Error in line " << LineNumber << endl;
return 2;
}
++LineNumber;
// Output the results to the console for testing.
cout << PointID << ": (" << x << ", " << y << ", " << z << ")" << endl;
}
return 0;
}
---------------------------------
You want to change it to read doubles. Just make the following change with no need to alter a format spec and manually make sure it matches the variables:
double x, y, z;
Steve
|
|
|
|
|
I want to modify the color in the bitmap displayed in a window on screen in real time, for exemple for simulating a transition night/day.
Some pixel may have their color modified, other not.
Please can you indicate how I can create some filter or lookup table in order to implement such function in Visual C++.
Use of CPalette ? Other ?
Thanks for your help.
jean-marc.nakache@neuf.fr
|
|
|
|
|
Use GetBitmapBits to retrieve data of bitmap that displayed in a device context . Then change bytes of color and use SetBitmapBits .
|
|
|
|
|
Hello,
How can i convert any file format to tiff file format? Any DLL, source code or free app via command line?
Alternatively, can be a solution that convert any file to another format and later to a tiff format.
Any idea?
[]'s
Cris.
-- modified at 15:48 Wednesday 12th July, 2006
|
|
|
|
|
GDI+ is a dll that you can redistribute, that comes with any VC version > 6, or is in the PSDK for VC6. It can load TIFF as well as JPG/GIF/PNG.
I *think* it loads tiff.....
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
As Christian said, use GDI+. Be aware that it supports only SOME TIFF files. (Look at TIFF as a container of an image; how the image is actually formatted/compressed is essentially infinite. Before you get too alarmed, there are TIFF formats Apple has never published.) Fortunately, GDI+ handles the more common formats.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
But using GDI+, can I convert any file format to tiff? Or only image file to tiff?
|
|
|
|
|
I don't understand your question since GDI+ only handles image files.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|