C Programming Homework.

Write a shell script to set an environment variable called HOW. How can be set to Char or Struct.

Use VI to create a file that has a fixed layout of 2 character fields.

Write a C program that takes in a filename as a parameter. If the HOW environment variable equals 'char', change the first and last character of the file to A. If the HOW environment variable is 'Struct', change the first row of your data using a structure to read and write the data. You can make any change you want. (It will be easiest to change one array element of a character array to the letter 'B' instead of manipulating strings.)

You may find that these programs we discussed in class serve as good references for this assignment:

feature demonstrated comment wget
write to a file using structure This example reads one file and writes another, while this assignment asks you to read and write the same file. To open a file for read/write, open it with O_RDWR instead of O_RDONLY wget http://home.adelphi.edu/~pe16132/csc271/note/scripts/fileio/demoenvfile3.c
write to a file using seek This example shows how you can use lseek to set your cursor to a particular point in a file. wget http://home.adelphi.edu/~pe16132/csc271/note/scripts/fileio/timestampwithseek.c
     


Hint:

Logic for managing this file: To change a file, open it for read/write, and then read the file, then make changes to the data you read, then possibly use lseek to set the write offset position, and then write the file.

Command guide: look for open, read, lseek, and write and getenv