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

  Why would you recommend a multi-core cpu

Discussion is designed to help you know the roles of hardware and software components in a modern computer system. For the purposes of this Discussion, assume that you are heading a team of 25 people working on a software development project.

  Produce a thresholded binary image

E27: Computer Vision Spring 2016 - PROJECT 1. Thresholding. Your system will produce a thresholded binary image where the non-zero pixels correspond to objects of interest (foreground), and the zero pixels correspond to background. You will need t..

  What are most crucial components of project implementation

What are the most crucial components of project implementation-hardware and software components or people and organizational components? Why?

  Determine the current gain of the circuit

Determine the current gain (13) of the circuit in Figure 5.6(a) if R1, = 8 KO and /lc = 500 fl.

  Write a procedure that receives a binary file time value

Write a procedure that receives a binary file time value in the AX register.

  Stack pointer and program counter

The content of top of a memory stack is 5320. The content of stack pointer SP is 3560. A two-word call subroutine instruction is situated in the memory at address 1120 followed by the address field of 6720 at location 1121.

  Define challenges that network forensics investigations pose

In the "Practical Investigative Strategies" chapter of your course textbook, you were introduced to network forensics investigations.

  Creating new information technology systems for a company

Creating new information technology systems for a company requires the staff to understand reasoning and operation of the systems in which they interact. How will you create the support needed to create the recommended information systems and prep..

  Write java syntax that declares a 1d integer array

Write Java syntax that declares a 1D integer array. Instantiate and initialize the array from Q#1 with values: 5, 3, 5, 7,

  What is the latency of the instruction

Assuming a Store Word instruction passes through this pipeline, and doesn't actually use hardware in Write Back phase, what is the latency of the instruction?

  How might you mitigate the risk

Assume that you are the project manager for an upcoming new information systems project designed to replace your organization's old inventory management system.

  Write a assembly language program to generate a square wave

Write a PIC18F assembly language program to generate a square wave on pin 3 of PORTC with a 4 ms period using Timer3 in 16-bit mode with a prescaler value.

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