Question
Asked 5th Dec, 2013

I am working on compressing a file. I would like to know how to compress a file using C programming?

My compression algorithm majorly depends on opening a file in 0 and 1's i.e Binary and applying a compression algorithm to it . Can anyone help me ?

Most recent answer

run this code and understand the program flow automatically you get idea how its working. just remove the existing code into your proposed work source code.also first write pseudo code for your compression algorithm.Best of luck and happy coding

All Answers (10)

5th Dec, 2013
Swapneel Pimparkar
Qualcomm
Technically, Encryption and Compression are two different activities though at times, doing one thing results in another (e.g. encrypting audio in certain form also compresses it). I suppose you want to just compress the file. What you are trying to do is binary compression. It does not necessarily mean that all compression is done only at binary level. Depending upon the data that you are trying to compress, the algorithms may change. It is best to know at least popular data compression algorithms beforehand so that you can code on your own.
7th Dec, 2013
Anthony Vinay
PES School of Engineering
Thank you sir . But I would like to perform a compression at binary level using C/C++ . How can I do it is my question ?
10th Dec, 2013
Samuel Deleplanque
IEMN - JUNIA
Do you want an library or to code your own encryption algorithm?
13th Dec, 2013
Anthony Vinay
PES School of Engineering
To code my own encryption algorithm .
15th Dec, 2013
Ozan Çağlayan
Imperial College London
28th Dec, 2013
Tayfun Kucukyilmaz
TED Universitesi
huffman coding is one of the best methods for compressing a file. What you basically do is to check occurence frequencies of letters, groups of letters, or words (whatever your level of requirement is) and assign a number to it. For example the most frequent element will be assigned to the number that can be representable with the least number of bits and the least freuqent the most. However huffman requires the mapping table stored as well. Gaussian encoding is another compression scheme that does not require global knowledge.
Also you may have other requirements, such as being able to uncompress a substring without uncompressing everything. So, theres a lot for compression actually
The book "Managing Gigabytes" is an excellent resource for compression, gives a comprehensive explanation to all these algorithms if you have access to it
2 Recommendations
2nd Jan, 2014
David Fernández Piñas
Telespazio Belgium
For compression/decompression of huge text files in C (hundredths of MB), I have used the zlib. I suppose it should work also for binary files.
run this code and understand the program flow automatically you get idea how its working. just remove the existing code into your proposed work source code.also first write pseudo code for your compression algorithm.Best of luck and happy coding

Similar questions and discussions

Can anyone help with a problem compiling program related to " Network & Int. Programming in C" ?
Question
8 answers
  • Rajmani JhaRajmani Jha
Following Errors get displayed after compiling:
1.cannot find -lobjc
2.id returned exit 1 status
#include "stdafx.h"
#include<windows.h>
#include<winsock.h>
#define NETWORK_ERROR -1
#define NETWORK_OK 0
int APIENTRY WinMin(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR IpCmdLine,int nCmdShow)
{
WSADATA ws;
int nret;
// Initialize Winsock
WSAStartup(0x0101,&ws);
//Create the socket
SOCKET commsocket;
commsocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(commsocket==INVALID_SOCKET)
{
MessageBox(0,"Could not create comm. socket","Error",0);
WSACleanup();
#include "stdafx.h"
#include<windows.h>
#include<winsock.h>
#define NETWORK_ERROR -1
#define NETWORK_OK 0
int APIENTRY WinMin(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR IpCmdLine,int nCmdShow)
{
WSADATA ws;
int nret;
// Initialize Winsock
WSAStartup(0x0101,&ws);
//Create the socket
SOCKET commsocket;
commsocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(commsocket==INVALID_SOCKET)
{
MessageBox(0,"Could not create comm. socket","Error",0);
WSACleanup();
...................

Related Publications

Book
Full-text available
Questo testo propone un percorso didattico che, procedendo attraverso esempi, esercizi e problemi di difficoltà crescente, presenta gli elementi fondamentali del linguaggio di programmazione C e, al tempo stesso, si sofferma ad analizzare gli aspetti algoritmici e di efficienza computazionale che conducono alla progettazione di soluzioni efficaci e...
Article
TABLA DE CONTENIDO CONCEPTOS BASICOS CONCEPTOS BASICOS DE C OPERADORES Y EXPRESIONES ENTRADA Y SALIDA DE DATOS PREPARACIÓN Y EJECUCIÓN DE UN PROGRAMA EN C INSTRUCCIONES DE CONTROL FUNCIONES ESTRUCTURA DE UN PROGRAMA ARRAYS PUNTEROS ESTRUCTURAS Y UNIONES ARCHIVOS DE DATOS PROGRAMACIÓN A BAJO NIVEL CARACTERÍSTICAS ADICIONALES DE C SISTEMAS DE REPRE...
Conference Paper
Full-text available
La adaptación al Espacio Europeo de Educación Su- perior ha supuesto el rediseño de parte de los pla- nes de estudios por parte de las universidades. En este artículo se describe el proceso de concepción, diseño y despliegue de una asignatura de programa- ción en C que incluye como principales novedades la adopción de una metodología de aprendizaje...
Got a technical question?
Get high-quality answers from experts.