Click here to Skip to main content
15,917,565 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: recv no blocking Pin
Albert Holguin1-Jul-15 4:02
professionalAlbert Holguin1-Jul-15 4:02 
GeneralRe: recv no blocking Pin
Albert Holguin30-Jun-15 13:27
professionalAlbert Holguin30-Jun-15 13:27 
QuestionCan a modeless Dialog Box be a main window "m_pMainWnd" Pin
ForNow29-Jun-15 5:07
ForNow29-Jun-15 5:07 
AnswerRe: Can a modeless Dialog Box be a main window "m_pMainWnd" Pin
Richard MacCutchan29-Jun-15 5:12
mveRichard MacCutchan29-Jun-15 5:12 
GeneralRe: Can a modeless Dialog Box be a main window "m_pMainWnd" Pin
ForNow29-Jun-15 5:22
ForNow29-Jun-15 5:22 
QuestionCan anybody help me with converting this example for x64? Pin
Member 802436529-Jun-15 2:42
Member 802436529-Jun-15 2:42 
SuggestionRe: Can anybody help me with converting this example for x64? Pin
Richard MacCutchan29-Jun-15 3:36
mveRichard MacCutchan29-Jun-15 3:36 
QuestionQ: CTreeCtrl: How to over-ride default selection of item Pin
ShivaPrasadGadapa28-Jun-15 23:43
ShivaPrasadGadapa28-Jun-15 23:43 
QuestionDraw in front of bitmap Pin
lor7527-Jun-15 8:11
lor7527-Jun-15 8:11 
AnswerRe: Draw in front of bitmap Pin
Richard MacCutchan27-Jun-15 21:11
mveRichard MacCutchan27-Jun-15 21:11 
GeneralRe: Draw in front of bitmap Pin
lor7527-Jun-15 22:22
lor7527-Jun-15 22:22 
QuestionClass or object? Pin
Vaclav_26-Jun-15 5:32
Vaclav_26-Jun-15 5:32 
SuggestionRe: Class or object? Pin
David Crow26-Jun-15 5:54
David Crow26-Jun-15 5:54 
AnswerRe: Class or object? Pin
Maximilien26-Jun-15 7:24
Maximilien26-Jun-15 7:24 
AnswerRe: Class or object? PinPopular
CPallini26-Jun-15 8:05
mveCPallini26-Jun-15 8:05 
GeneralRe: Class or object? Pin
Albert Holguin26-Jun-15 10:26
professionalAlbert Holguin26-Jun-15 10:26 
AnswerRe: Class or object? Pin
Albert Holguin26-Jun-15 10:30
professionalAlbert Holguin26-Jun-15 10:30 
AnswerRe: Class or object? Pin
Stefan_Lang30-Jun-15 23:50
Stefan_Lang30-Jun-15 23:50 
GeneralRe: Class or object? Pin
_Flaviu1-Jul-15 22:17
_Flaviu1-Jul-15 22:17 
GeneralRe: Class or object? Pin
Stefan_Lang1-Jul-15 22:36
Stefan_Lang1-Jul-15 22:36 
GeneralRe: Class or object? Pin
_Flaviu2-Jul-15 1:21
_Flaviu2-Jul-15 1:21 
AnswerRe: Class or object? Pin
Kevin McFarlane6-Jul-15 23:16
Kevin McFarlane6-Jul-15 23:16 
QuestionVery simple binary file compressor in C Pin
stonemanhero26-Jun-15 1:52
stonemanhero26-Jun-15 1:52 
Hello as subject says i am trying to make some simple binary file compressor (for now). I started with basics.
This code opens file in binary mode reads byte by byte and input bytes writes to output "compressed" file. If byte == 0x00 counts number of 0x00's and writes 0x00 and number of 0x00's.

C++
#include<stdio.h>
#include<stdlib.h>

int main()
{
	int i, duzina, stanje=0, brojac=0;
	unsigned char chr;
	FILE* ulaz = fopen("../testapp/testapp", "rb");
	FILE* izlaz = fopen("../testapp/testapp.zip", "wb");
	
	if(ulaz == NULL)
	{
		printf("Problem with file!\n");
		exit(1);
	}
	if(izlaz == NULL)
	{
		printf("Problem with output file!\n");
		exit(1);
	}

	fseek(ulaz, 0, SEEK_END);
	duzina = ftell(ulaz);
	fseek(ulaz, 0, SEEK_SET);

	for(i=0; i<duzina; i++)
	{
		chr = fgetc(ulaz);
		if(chr == 0x00) 
		{
			if(stanje == 0)
			{
				stanje=1;
				brojac=1;
			}
			else
				brojac++;
		}
		else
		{
			if(stanje == 0)
				fputc(chr, izlaz);
			else
			{
				fputc(0x00, izlaz);
				fwrite(&brojac, sizeof(int),1,izlaz);
				fputc(chr, izlaz);
				printf("%d ", brojac);
				stanje=0;
				brojac=0;
			}
		}
	}

	fclose(izlaz);
	fclose(ulaz);
}




To "decompress" file i use this code which as input have "compressed" file and read byte by byte if byte == 0x00 reads integer and write N times 0x00 (N value = readed integer)

C++
#include<stdio.h>
#include<stdlib.h>

int main()
{
	int i,j, duzina, brojac=0;
	unsigned char chr;

	FILE* ulaz = fopen("../testapp/testapp.zip", "rb");
	FILE* izlaz = fopen("../testapp/testapp1", "wb");
	
	if(ulaz == NULL)
	{
		printf("Problem with file!\n");
		exit(1);
	}
	if(izlaz == NULL)
	{
		printf("Problem with output file!\n");
		exit(1);
	}

	fseek(ulaz, 0, SEEK_END);
	duzina = ftell(ulaz);
	fseek(ulaz, 0, SEEK_SET);

	for(i=0; i<duzina; i++)
	{
		chr = fgetc(ulaz);
		if(chr == 0x00)
		{
			fread(&brojac, sizeof(int), 1, ulaz);
			printf("%d ", brojac);
			for(j=0; j<brojac; j++)
				fputc(0x00, izlaz);
			i+=4;	
		}
		else
			fputc(chr, izlaz);
	}

	fclose(izlaz);
	fclose(ulaz);
}



So my problem is that when "decompressing" is finshed some bytes are missing (program works correct).

Byte comparing:

[stone@hero testapp]$ diff testapp1.hex testapp.hex 
443,444c443,444
< 0001c00 0001                                   
< 0001c01
---
> 0001c00 0001 0000 0000 0000 0000 0000 0000 0000
> 0001c10
[stone@hero testapp]$


I'm on: Linux hero 3.18.15-1-MANJARO #1 SMP PREEMPT Sun Jun 14 10:09:07 UTC 2015 x86_64 GNU/Linux if it matters.

Source code for test app:
C++
#include<stdio.h>
#include<time.h>

main()
{
	srand(time(NULL));
	printf("\nHello, stone... ");
	printf("Your random number is: %d\n\n", rand() % 100 + 1);
}



What can be a problem with missing bytes?
AnswerRe: Very simple binary file compressor in C Pin
CPallini26-Jun-15 3:00
mveCPallini26-Jun-15 3:00 
QuestionCreating a standalone exe with Visual Studio 2013 native unit tests? Pin
Joe Woodbury25-Jun-15 10:53
professionalJoe Woodbury25-Jun-15 10:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.