|
See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Thanks David.
“If I had asked people what they wanted, they would have said faster horses.”
― Henry Ford
|
|
|
|
|
How to create Bitmap of 8bpp from 8bpp RAW data?
|
|
|
|
|
0. open a file
1. fill out and write the BITMAPFILEHEADER
2. fill out and write a BITMAPINFOHEADER
3. write the 256 palette entries
4. write the pixel rows, bottom-to-top, padded on the ends so that the rows are multiples of 4 bytes each
5. close the file
|
|
|
|
|
|
Ahhh, well that's a different kettle of fish altogether.
You'll need to look into colour quantization.
You'll have to work out a way of converting the potentially 16.7 million colours into a maximum of just 256 colours. Oct-tree colour quantization is one method that comes to mind. Here's something of a brutal introduction to the topic. http://www.cubic.org/docs/octree.htm[^] By the time I'd implemented that one back around 98 or 99 sometime, I got rid of my 16 bit vid card and replaced it for a tru-colour one. Shame really, but so much easier to work in 24 bit colour.
There are (much much) simpler methods that will work if there are less that 257 distinct colours in the image.
|
|
|
|
|
Hi,
I want to read line from a file and after reading that line i have to delete that line.I think deleting a line in file is difficult.So i thought to replace the line with null string.
For that i coded below..first i test with text "TEST" for updating.But i could not get that.
if ( (fpExe=fopen((LPCTSTR)sExePath, "r+"))!=NULL)
{
while(fgets(List,80,fpExe)!=NULL)
{
sReadLine = List;
off1 = ftell(fpExe);
result = fseek( fpExe, off1,SEEK_SET);
fprintf( fpExe, "%s", "TEST" );
}
fclose(fpExe);
return false;
}
else
{
return false;
}
Example:
INSTRUCTOR1
INSTRUCTOR2
this should become
TEST
TEST
But actually what comes as
INSTRUCTOR1
TESTRUCTOR1
So how can i replace string with null or another string.
|
|
|
|
|
As far as you open the file in read mode, you can not write anything in that file ...
|
|
|
|
|
What are you trying to do, exactly?
If you need to manipulate the content of a file the usual way is:
- Read the file content into memory.
- modify it
- Write the modified content to another file (say "output").
- delete the original file and rename the "output" file you produced with the original filename.
Veni, vidi, vici.
|
|
|
|
|
You cannot do it that way; a file is merely a stream of bytes and overwriting something with a shorter value will leave garbage in the stream. You need to follow something similar to my response here[^], but using text instead of PDF files and changing lines rather than pages. If you want to delete a line then merely read it and ignore it.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
Just to amplify CPalini's answer - if you're doing line oriented I/O then open the file for reading, open another for writing then process each line from the input file putting the results in the output file.
Another thing you could try is have fixed length records in the file. Then to read a record all you have to do is fseek to (record_size * index_of_record) . To replace it you just write to the same place and to erase it you just mark the entry as empty somehow. This means you only need a single file open but makes the logic a bit more complicated.
Cheers,
Ash
|
|
|
|
|
HI guys,
How to read data from a file and save that data
|
|
|
|
|
See here[^], paying particular attention to CreateFile() , ReadFile() and WriteFile() .
[edit]
On second thoughts you may be better to start here[^] for pure C.
[/edit]
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
Is there a multiprocessor implementation of qsort and bsearch out there? My app. is mostly in C but some bits have got C++ and STL depending on what libraries are needed. We compile with VS2008 so openMP is available.
|
|
|
|
|
An article I read recently on sorting in parallel: http://www.drdobbs.com/blogs/parallel/232600358?pgno=1[^]
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
|
hi,
i
int COMportNum= 3;
portstream_fd COMstream;
portstream_fd pstream;
char COMportPrefix[10] = "COM";
char COMportName[256];
sprintf(COMportName, "%s%d", COMportPrefix, COMportNum);
strng = CString(COMportName);
strng.Format(_T("%0.9s"), strng);
SetDlgItemText(IDC_STAT, strng);
set_baud_rate(BaudRate);
COMstream = open_host_port(COMportName);
if ( COMstream == PORT_NOT_OPENED )
{
stw.Format(_T("%08X"), GetLastError());
SetDlgItemText(IDC_PTUPORT, stw);
}
else
SetDlgItemText(IDC_PTUPORT, (LPCTSTR) L"Ok");
can anyone please help me with this error.
Regards
Jawad
|
|
|
|
|
Hi there,
I don't want to seem pedantic, though I will point out that this is not actually system error 0x0000007B, but rather the error-code of the last system function that failed. A system error is one generally regarded as having been generated by Windows itself (rather than just a 'helper' function)
Something that you may choose to do which certainly clarifies the error is to display a description of the error.
Have a look over here, for a method by which the code 0x7B may be turned into a text message.
|
|
|
|
|
The error message is (you can check it in WinError.h )
What library are you using?
Veni, vidi, vici.
|
|
|
|
|
basically i have the console program running fine (means having source file and header files). than i wanted to build GUI for this using MFC in vs2008. now i don't understand how to open serial port in MFC. code below shows how to open serial port in console programming using cmd prompt.
COMportName[0] = ' ';
while (COMportName[0] == ' ') {
printf("\nEnter the %s port number the PTU is attached to: ", COMportPrefix);
scanf("%d", &COMportNum);
printf("You selected %s%d. Is this OK? (enter 'y' or 'n'): ", COMportPrefix, COMportNum);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
if ( tmpChar == 'y' )
sprintf(COMportName, "%s%d", COMportPrefix, COMportNum);
}
tmpChar = 'f';
while (tmpChar != 'y') {
printf("\nEnter the baud rate the ptu is communicate at (default: 9600): ");
scanf("%d", &BaudRate);
printf("You selected %d. Is this OK? (enter 'y' or 'n'): ", BaudRate);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
}
set_baud_rate(BaudRate);
COMstream = open_host_port(COMportName);
if ( COMstream == PORT_NOT_OPENED )
{ printf("\nSerial Port setup error.\n");
goto abnormal_exit; }
printf("\nSerial port %s initialized\n", COMportName);
|
|
|
|
|
jawadali477 wrote: COMstream = open_host_port(COMportName);
I would use the debugger to watch COMportName content in both console and MFC applications.
Veni, vidi, vici.
|
|
|
|
|
console program is running fine. problem is in MFC program. can you tell how to implement the console program, as mentioned, in MFC??
|
|
|
|
|
What a mix up of different naming conventions!
|
|
|
|
|
As CPallini pointed out
CPallini wrote: The error message is (you can check it in WinError.h )
Are you sure COM3 exists on your machine?
Did you try the format \\.\COM3 instead?
What happens in set_baud_rate() and in open_host_port()? You have to open the COM-Port before changing the baudrate
Cou can find some more hints on serial communication here:
Communications Resources[^]
[Edit]corrected spelling of memeber name [/Edit]
modified 15-May-12 5:16am.
|
|
|
|
|
Andy411 wrote: JPalini
Veni, vidi, vici.
|
|
|
|