Write a program that accepts two command line arguments

Assignment Help Computer Engineering
Reference no: EM132207514

Question :

Write a program that accepts two command line arguments. The first is the name of a file that is to be used as the input file and the second is the name of the output file.

The program is to base-64 encode the first file, which is to be treated as a binary file, into the second. The first line of the output file, which is a text file, should contain the name of the first file (so that the reconstructed data can be placed in a file of the correct name later).

Your program should print to the console the total number of bytes contained in the input file.

This is what i have so far

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

int BUFFER_SIZE = 3;
FILE *source;
FILE *destination;
int n;
int count = 0;
int written = 0;

char map(unsigned value)
{
if (value < 26) return 'A' + value;
if (value < 52) return 'a' + value - 26;
if (value < 62) return '0' + value - 52;
if (62 == value) return '+';
if (63 == value) return '/';

return '?';
}

unsigned unmap(char c)
{
if ('/' == c) return 63;
if ('+' == c) return 62;
if (isdigit(c)) return 52 + (c - '0');
if (islower(c)) return 26 + (c - 'a');
if (isupper(c)) return 0 + (c - 'A');

return 0xFFFFFFFF;
}

int main(void)
{
char fname[128];
printf("Enter .txt file name to read\n");
scanf("%s",fname);
strcat(fname,".txt");
source = fopen(fname,"rb");

char outname[128];
printf("Enter .txt file name to print\n");
scanf("%s",outname);
strcat(outname,".txt");
destination = fopen(outname,"wb");

unsigned char buffer[BUFFER_SIZE];
unsigned data;

int i = 0;

if (source) {

while (!feof(source)) {

n = fread(buffer, 1, BUFFER_SIZE, source);
count += n;

data =buffer[0];


// printf("MSG : ");
for (int i = 0; i < 3; i++)
{
//
// buffer[i] = map(buffer[i]);
printf("\n%d", buffer[i]);
}
// printf("The contents of buffer[] are %s\n", buffer);
fwrite(buffer, 1, n, destination);
}
printf("\n%d bytes read from library.\n", count);
} else {
printf("fail\n");
}

// for (int i = 0; i < lengthOfFile; i++)
// {
// unsigned value = (data >> (18 - 6 * i)) & 077;

// chars[i] = map(value);
// }

// printf("MSG : ");
// for (int i = 0; i < lengthOfFile; i++)
// {

// printf("%c", chars[i]);
// }
// printf("\n");

// data = 0;
// for (int i = 0; i < lengthOfFile; i++)
// {
// unsigned value = unmap(chars[i]);

// data <<= 6;
// data += value;
// }

// printf("DATA: %o\n", data);

fclose(source);
fclose(destination);

return EXIT_SUCCESS;
}

in the input file i have -- 062434752

it should print to the output file -- yjnq

Reference no: EM132207514

Questions Cloud

Write a php script that checks a word or a phrase : Write a PHP script that checks a word or a phrase (stored in a string variable) to determine if it is a standard palindrome.
Multiplies a number by another by repeated addition : Write a Pep/9 assembler program that multiplies a number by another by repeated addition.
A program that multiplies a number by shifting left : Write a Pep/9 assembler program that multiplies a number by shifting left. Each shift left doubles the number.
What strategic alternatives is starbucks company using : What strategic alternatives is Starbucks company using? Who are Starbucks competitors?
Write a program that accepts two command line arguments : Write a program that accepts two command line arguments. The first is the name of a file that is to be used as the input file.
About the increasing use of restrictive covenants : What do you think about the increasing use of restrictive covenants?
Find p using the appropriate model : Suppose that 25% of all licensed drivers in a state do not have insurance. Let X be the number of uninsured drivers in a random sample of size 64.
What are social entrepreneurs and social intrapreneurs : What are social entrepreneurs and social intrapreneurs? Share some examples of how Knowledge Management can help an organization make better decisions.
Create a stock portfolio of australian corporations : Determine whether your foreign stock prices are highly correlated - Determine whether your foreign stocks performance is driven by the Australian market

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd