C/C++ :: Zip And Unzip Files Using Huffman Encoding

Apr 14, 2015

I am writing a program to zip and unzip files using Huffman Encoding. I have successfully Built my Huffman Tree but I am unable to traverse through it to retrieve code the code for each character in sample files using the GetCode() method.

Here is my zip.cpp file:

#include <iostream>
#include <fstream>
#include <algorithm>
#include <cctype>
#include "huffman.h"
using namespace std;
void CountLetters(int frequency[]);
int main(int argc, char *argv[]) {

[Code] ....

Specifically I am having trouble with the following segment in zip.cpp where I want to go through my built tree and print out each character and it's associated ascii value using the GetCode() method in huffman.cpp

cout << " Here are the codes: "<< endl;
for(char ch = char(0); ch <= char(255); ch++)
//for(int i= 1; i < 256; i++ )
{ //int x = (char) i;
if(mytree.inTree('*'))

[Code] ....

View 8 Replies


ADVERTISEMENT

C/C++ :: Encoding And Decoding Text From TXT Files

Dec 4, 2014

I'm new to C++ and involving encoding and decoding text from text files. When I enter a file in the program just stalls.

#include <iostream >
#include <iomanip>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;
char getmenuselection (char m);

{Code] .....

View 3 Replies View Related

C :: Mcrypt Lib And String Encoding

Feb 11, 2015

I've got an application here which connects over the internet to a webserver and sends some json strings. This is all working already.

Now I want to encode one string via mcrypt (because it seemed the easiest library of all) AES and send it over to the other server where it should get decrypted again and checked for validity.

I'll be using this sample code as "starting base". i've found it on the internet:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*
* MCrypt API available online:

[Code] ....

The code works as it is, it encodes my string into a ciphered text and displays the text via the display function to stdout.

From previous projects I know I usually used Base64 for transporting strings via json, but in this example the string is encoded into "%d" - so decimals.. It works too, and I dont care if I send a base64 encoded string or these decimals but how would I calculate back the %d encoded string ? So how would a "undisplay()" class look alike ?

Or maybe there is an easier way to transport the string and re-decode it ?

I'd expect something like:

base64string = base64encode(ciphertext);
...
send base64string to host2
...
at host2:
ciphertext = base64decode(base64string)
...
and then mcrypt_decode that ciphertext...

View 1 Replies View Related

C :: How To Write In DOS Encoding Using Class FILE

Dec 12, 2013

How to write in DOS encoding using class FILE ?

View 5 Replies View Related

C++ :: Encoding Byte Array Data?

Apr 23, 2012

I'm trying to parse some binary data in the form of an array of bytes and I've come across something that is confusing me related to the representation of data as chars versus ints. It's a bit of a long story, but the byte array contains a mixture of character data and integer data which I' having trouble unravelling. The problem seems to arise from the issue below:

Code:
const char * ch_arr = "abcd";
const unsigned int * ui_arr = (const unsigned int*)ch_arr;
cout << ui_arr[0] << endl;
unsigned int ui = 'a';
ui = ui << 8;
ui |= 'b';
ui = ui << 8;
ui |= 'c';
ui = ui << 8;
ui |= 'd';
cout << ui << endl;

I expected both the output lines to be the same, since they contain the same bytes (I believe), but I get:

Code:
1684234849
1633837924

View 4 Replies View Related

C/C++ :: Writing A Program Which Includes Encoding And Decoding A Message?

Oct 31, 2014

I am writing a porgram which includes encoding and decoding a message.Now I am doing the encoding part.

The goal is to encode a message using similar approach as Caesar Cipher. But instead of alphabets, I am going to use the entire ASCII code of total 128 codes to be the base.

And it is not a simple shifting, it is a rotation. This means if you want to shift 4 units from char <DEL>, it will come back to the first code in ASCII Code which is at dec 0 char <NUL> and starts the shifting again. It won't jump if the limit of ASCII Code is reached.

Here we've got 7 different malls' names and I am going to encode them with a shift n. I think n is free to set, so here I just set it as 5. This is also called the key.

I have written something and I think it should work, but after all it doesn't. And I don't get what is wrong.

Here is my program:

#include <iostream>
using namespace std;
const int NUMBER_OF_MALLS = 7;
const int MALL_NAME_LENGTH = 13;
const int NAME_SIZE = MALL_NAME_LENGTH + 1;
void encode(int key, char plain[], int length, char encoded[]) {
for (int i = 0; i < MALL_NAME_LENGTH; i++)

[code].....

Note that I am not going to use other libraries, just <iostream>.

View 13 Replies View Related

Visual C++ :: Transferring Unicode String From One Program To Another With UTF-8 Encoding?

Mar 20, 2015

I'm transferring a unicode string from one program to another with UTF-8 encoding.

Program that is sending:

Code:
// Convert path
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_converter;
CString arg = L" /PATH="" + CString(utf8_converter.to_bytes(path).c_str()) + L""";

Program that is retrieving:

Code:
// Restore original path
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_converter;
std::wstring path = utf8_converter.from_bytes( argument );

Everything has worked fine, until running on a Japanese edition of Windows.

The "byte path" then looks something like "C:¥Users¥d✝?✝a ,?¥AppData¥Local¥Temp¥file.txt".

"from_bytes()" will throw an std::range_error exception "bad conversion".

The program works fine when working with Japenese writing inside paths in the English edition.

What could be causing the "bad conversion"?

View 10 Replies View Related

C# :: Filtering Invalid Byte Sequences For UTF8 Encoding For A Postgre?

Jun 25, 2014

Basically, I am inserting data from an ODBC connection into a PostgreSql database using the COPY query, but the COPY query stops and returns this error...

Quote
ERROR: invalid byte sequence for encoding "UTF8": 0x92
CONTEXT: COPY [TableName], line 1: "189572|1-00-1202|1-|00-|1202||AP||1...
STATEMENT: COPY [TableName] FROM STDIN (DELIMITER '|', NULL '')

View 4 Replies View Related

C++ :: Universal Order / Spacing Of Character Encoding For Integer Digits?

Feb 7, 2012

I have a char *pch that points to an integer digit 1 or 2 or ... 9. To get the character that's 1 less, instead of converting to int, minus 1, then converting back to char, I tried (*pch -1) and that seemed to work. I suppose that's because the particular character encoding on my system is such that the digits are encoded in the same order and spacing as the integers they represent. So the question is does this "convenience" feature hold true for all character encoding systems?

View 10 Replies View Related

C :: Program To Hide Files Behind Other Files Using Alternate Data Streams

Apr 5, 2013

I am writing a program to hide files behind other files using Alternate Data Streams in Windows NTFS file systems.

The program is as follows:

Code:

#include <stdio.h>
#include <stdlib.h>
int main(void){
char hostfile[75], hiddenfile[75], hiddenFileName[15] ;
printf("Enter the name(with extension) and path of the file whose behind you want to hide another file: ");
scanf("%75s", hostfile);

[Code]...

The complier is showing error as "Extra Perimeter in call to system" but I am not getting where?

View 4 Replies View Related

C++ :: Display Last 1000 Lines From Multiple Text Files (log Files)

Jan 16, 2014

I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.

I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.

What is the best way to do this? Even an outline algorithm will work.

View 6 Replies View Related

Visual C++ :: Should Precompiled Header Files Also Be Included In Source Header Files?

Sep 16, 2013

When including a header file in stdafx.h, should that file still be included in the source file where it is actually used?

If it is included in both places, is the one in the source file ignored?

View 5 Replies View Related

C++ :: Files Reading From PDF?

Feb 26, 2013

How do I read a .pdf file using C++? When I try to open it using myfile.open ("example.pdf"); but all I see is some Crazy Symbols. Is there any way to open ?

View 3 Replies View Related

C++ :: Comparison Of Two XML Files?

Feb 2, 2015

I need a program that can compare two xml files for equivalency using any XML Parser.

View 2 Replies View Related

C++ :: Cannot Take Input From Files

Apr 28, 2013

Assignment: Write a program that merges the numbers in two files and writes all the numbers into a third file. your program takes input from two different files and writes it output to a third file. Each input file contains a list of numbers of type int in sorted order from the smallest to largest. after the program is run, the output file will contain all the numbers in the two input files in one longer list in sorted order from smallest to largest. your program should define a function that is called with the two input - file streams and the out - put file stream as three arguments.

Okay, here is my code.

#include<iostream>
#include<fstream>
using namespace std;

int main() {
int list1[25];//array for the first list
int list2[25];//array for the second list

[Code] .....

I'm confused about where the two files (which contain lists of numbers) need to be placed in order to be read and if they need to be renamed or something.

View 1 Replies View Related

C++ :: Running Bat Files?

Oct 24, 2013

I want to know if you can run bat files from code? If so how else how can you shutdown a computer with code? OS is windows 7.

View 2 Replies View Related

C++ :: How To Upload The Files

Mar 19, 2014

So I am awful when having to use data or .txt files. I believe my code is right, I just don't know how to upload the files. Here is the description of the assignment and the coding:

Process the input file containing latitude and longitude data of US cities in degree, minutes, and seconds. Output the processed information in decimal degrees.

a) Write a C++ program to read each line of the input file, store each data line in an array of structure, calculate the degrees in decimal for latitude and longitude, store these values in the corresponding structure and write the results to the output file by processing the array.

b) Use vectors or dynamic array to optimize memory usage. Specify the design choice in your main comment for the program.

c) Split the City and State and store it in two separate fields.

d) Search a city and find it in the array of structure and print out ALL the information on the screen.

#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct City

[Code]...

View 3 Replies View Related

C++ :: Using Map And Writing Files

Dec 6, 2014

I'm using maps and writing files for the first time and I get a crazy compiler error when I try to compile the following code.

//map is named schedules
// saveSchedule() is a member of the Schedule class that writes a vector of objects to disk, or is supposed to
ofstream newFile("sched.txt");
map<string,Schedule>::iterator in;

[Code] .....

View 3 Replies View Related

C++ :: How To Loop Through Files

May 18, 2014

I have a program below that calculates the average, sum, etc of the numbers in a file named "mynumberlist1.txt".

I want to create a loop whereby the program loops through several files; mynumberlist2.txt, mynumberlist3.txt, and calculates the statistics for all relevant files using the calculations below. How would I do this?

#include <iostream>
#include <cmath>
#include <math.h>

[Code].....

View 1 Replies View Related

C++ :: Accessing Variables From Other Files

Sep 26, 2014

I don't have in depth code or anything. I tried this but can't seem to wrap my head around it.

Code: //header.h
namespace test {
int arr[5];

[Code] ....

Also tried putting int arr[5] in a Test class within test.h.

I have 2 structs in another file, the main, and want to make an instance of the arr variable, in a separate header, for each.

View 2 Replies View Related

C++ :: Calculations From Text Files?

Mar 31, 2014

I have a text file that contains values as follows:

2013 05 27 15 52 02.049824 231.401 0.022 49.738 2013 05 27 15 52 02.668822 229.814 0.019 49.738 2013 05 27 15 52 03.283705 228.528 2.599 49.726 2013 05 27 15 52 03.898469 230.140 2.576 49.751
Column1=date, Column2=Month, Column3=Day, Column4=Hour, Column5=Minute, Column6=Seconds, Column7=Voltage(Vrms), Column8=Current(Irms), Column9=Frequency(Hz).

I have to develop a program that will analyse these time-sampled voltage and current measurements over 24 hours and find the total energy used, mean and peak power consumption and Energy used over each hour of the 24 hour period.

How do I go about doing this? I also need to include at least one numerical integration technique. The file data contains over 50 thousand lines in the format mentioned above.

View 2 Replies View Related

C++ :: Parallel Arrays And Files

Mar 10, 2014

I am trying to learn about parallel arrays and files. I believe that I wrote a program that properly writes the data of the arrays into a file, but I am not quite sure how to take the next step and make a second program by bringing in the file I created and reading the information of the file back into two arrays to display them.

Code:
#include<iostream>
#include<fstream>
#include<string>
usingnamespace std;

[Code] ....

View 5 Replies View Related

C++ :: Loading Menu For Files

Jun 11, 2014

I would like to make a program that automatically launches and loads a file when a file of that file type is double clicked within windows. As said I am unsure where to look for some information as to how to do that, and so turn to you all. Is there a simple way of doing such a thing without using any external libraries, if so, a simple tutorial or link to a reference for this; if there is no way of doing this without externals what would be a small and simple to use library for this?

View 2 Replies View Related

C++ :: Working With Files In Netbeans

Jul 26, 2013

I have created a project in netbeans 7.2 and have not modified any setting. I have used all sorts of methods I could think/find but the code can not find the file.

I have placed my test.txt file in the folder of the project. Here is the location of the file:

C:UsersSAMARASDocumentsNetBeansProjects
eadFi le

However, I could not use it without modifying it as an absolute path.

For example, check the code from the FAQ. //well the return 0; is missing but this is not the problem now.

Or for example this code Code: bad code or with Code: myReadFile.open("C:/Users/SAMARAS/Documents/NetBeansProjects eadFile est.txt"); I have tried many things for placing the slashes, but could not find the file.

View 6 Replies View Related

C :: How To Upload And Navigate Files

Apr 23, 2013

i am new to c . is it possible to upload and navigate files in c . Any sample program.

View 5 Replies View Related

C :: Merging All TXT Files In A Directory

Dec 6, 2013

I'm writing a program to merge all .txt files in a directory. I had the code working and then made small change. It started crashing and I couldn't get it back to working.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>

[Code] ....

It's crashing around the

Code: while(!feof(in)){ .

If I comment that section out, the code still works. But, I know that portion of the code works to copy text from one file to another! It's actually from the Schildt complete C reference and I have tested it several times on it's own.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved