Question
Step one - read the assignment carefully and fully. Do each step and don't read more into it then is there. Step two of this
Step one - read the assignment carefully and fully. Do each step and don't read more into it then is there.
Step two of this assignment is to review the provided header file assignmet2.h. You will see a large number of #define statments the represent different computer lanaguages. Then there is a stucture called personalInfo. This is the structure you will allocate and populate. Next there is a #define of BLOCK_SIZE set to 256 this is going to be your buffer size to transform byte data into block data. Finally there are the prototypes for 4 functions that you will need and are described in the steps below. Note that the functions are implemented in provided assignment2.o file, you do not implement them.
Step three is to remember some of the rules. Name your c file according to our standard of lastname_firstname_HW1_main.c, edit the Makefile to enter your FIRST and LAST name (this Makefile is a little different then the first one - do not change anything other than the variables FIRSTNAME and LASTNAME). Make sure to comment your code, have the standard header. Remember that for every malloc, there must also be a corresponding free. Use printf's to debug your program. In keeping code neat and readable, lines in your program (including commments) should be kept to about 80 characters long but never more than 100 characters.
Now what is the coding portion of this assignment...
Step four is to allocate (using malloc) an instantiation of the personInfo structure and to populate it. The firstName and the lastName are populated from the 1st and second command line argument. You will then assign your student ID to the studentID field, you will populate the level (gradelevel) appropriately. You will then populate the languages field. To do so, specify every language you have Knowledge of and there must be at least three (by definition, with the prerequisites for the course you should at least know some Java, C++, some assembler and of course now C. But, include all you have knowledge of. The last part of populating the structure is to copy the third command line parameter to the message field. Do note the length of the message field.
Step five is to "write" your personal information structure by calling writePersonalInfo which is one of the function prototypes in the assignment2.h file. The return value from the function is 0 if it succeeds.
Step six involves getting a series of C stings (you do not know how many or how long each one it or what it contains). You get these strings by calling the function getNext. The return value is a char * (C string). If the return value is NULL then you have finished. You will copy the contents of each of those strings into a buffer (block) that is BLOCK_SIZE (use malloc to allocate the buffer), as the buffer is filled you will commit the buffer by calling commitBlock passing in the pointer to your BLOCK_SIZE buffer. Note: You must copy the data into the buffer in chunks using memcpy (not character by character).
Step seven if the final coding step. Call the function checkIt, then exit main returning the same value as returned from checkIt.
Step eight is dependent on checkIt running correctly and displays some binary data as a hexdump which is the personalInfo structure. You are to describe what each element is, use the structure as reference and show the values and how to read those values. i.e. which bytes are the student ID, what is it's hexadecimal value and if that is converted to decimal is it correct? You are to prove that each value in the structure is correct and why it is correct. The purpose is so that you can be sure that what you thought should be written is actually written. Use color highlights and start and end addresses to describe each element from the hexdump output.
The following is an example (with incorrect selections) to give you the idea of what your analysis should look like.
NOTE:- IN CASE OF ANY QUERY PLEASE DO ASK IN COMMENT ANYTIME.............HAPPY LEARNING AND KEEP CHEGGING.....
Source code for main.c:
#include
int main(int argc, char *argv[]){ const char *next; char buffer[BLOCK_SIZE];
/*allocating memory to object of type personalInfo*/ personalInfo *myInfo=(personalInfo *)malloc(sizeof(personalInfo));
/*if memmory allocation failed*/ if(myInfo==NULL){ printf("error occured while instantiaing personl info "); } /*To assign values in struct -> is used , here we assign firstname, lastname which are provided by the command line argument and assign values to variables student id and level*/ myInfo->firstName=argv[1]; myInfo->lastName=argv[2]; myInfo->studentID=12345; myInfo->level=SENIOR;
/* bit wise or the mask of all languaes and add to it to personal info */ myInfo->languages =KNOWLEDGE_OF_C | KNOWLEDGE_OF_JAVA | KNOWLEDGE_OF_JAVASCRIPT;
/*copying meesage from command line arg to personalINfo*/ strcpy(myInfo->message,argv[3]);
/*writing personal info*/ int r=writePersonalInfo (myInfo); if(r==0){ printf("error occured while writting personl info "); return r; } else{ }
int len=0; int i=0;
/*get the first string*/ next= getNext();
/*keep looping untill NULL is recieved, get the length of the received string, fill the block buffer with recieved bytes then a single character is copied at a time. Check if buffer is filled, if filled then commit buffer, empty the buffer and set the index to 0 */ while(next!=NULL){ len=strlen(next); for(int k=0;k /*if NULL recieved and last filled buffer was not commited as it was not full filled*/ if(i!=0){ commitBlock(buffer); } /*calling check to print the hexadecimal characters*/ r=checkIt(); /*freeing memory*/ free(myInfo); return r; } Source code for assignment2.h: #define KNOWLEDGE_OF_C 1 #define KNOWLEDGE_OF_JAVA 2 #define KNOWLEDGE_OF_JAVASCRIPT 4 #define KNOWLEDGE_OF_PYTHON 8 #define KNOWLEDGE_OF_CPLUSPLUS 16 #define KNOWLEDGE_OF_PASCAL 32 #define KNOWLEDGE_OF_FORTRAN 64 #define KNOWLEDGE_OF_RUBY 128 #define KNOWLEDGE_OF_ADA 256 #define KNOWLEDGE_OF_LISP 512 #define KNOWLEDGE_OF_SQL 1024 #define KNOWLEDGE_OF_HTML 2048 #define KNOWLEDGE_OF_SWIFT 4096 #define KNOWLEDGE_OF_PROLOG 8192 #define KNOWLEDGE_OF_C_SHARP 16384 #define KNOWLEDGE_OF_PL1 32768 #define KNOWLEDGE_OF_INTEL_ASSEMBLER 65536 #define KNOWLEDGE_OF_IBM_ASSEMBLER 131072 #define KNOWLEDGE_OF_MIPS_ASSEMBLER 262144 #define KNOWLEDGE_OF_ARM_ASSEMBLER 524288 #define KNOWLEDGE_OF_COBOL 1048576 #define KNOWLEDGE_OF_APL 2097152 #define KNOWLEDGE_OF_R 4194304 #define KNOWLEDGE_OF_OBJECTIVE_C 8388608 #define KNOWLEDGE_OF_BASIC 16777216 #define KNOWLEDGE_OF_PHP 33554432 #define KNOWLEDGE_OF_GO 67108864 typedef struct personalInfo { char * firstName; char * lastName; int studentID; enum gradelevel {FRESHMAN, SOPHMORE, JUNIOR, SENIOR, GRAD, INSTRUCTOR} level; int languages; // See #defines for the bitmap values char message[100]; } personalInfo; #define BLOCK_SIZE 256 int writePersonalInfo (personalInfo * pi); //Write your personal info structure const char * getNext(void); //Get the next line to buffer write void commitBlock (char * buffer); //Flush out your 256 byte Buffer int checkIt (void); //Called at the end of your program to check the results Source code for Makefile: FIRSTNAME=John LASTNAME=Doe ROOTNAME=$(LASTNAME)_$(FIRSTNAME)_HW HW=2 FOPTION=_main # DO NOT CHANGE the RUNOPTIONS RUNOPTIONS=$(FIRSTNAME) $(LASTNAME) "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal." CC=gcc CFLAGS= -g -I. # To add libraries, add "-l %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) $(ROOTNAME)$(HW)$(FOPTION): $(OBJ) $(CC) -o $@ $^ $(CFLAGS) $(LIBS) clean: rm $(ROOTNAME)$(HW)$(FOPTION).o $(ROOTNAME)$(HW)$(FOPTION) run: $(ROOTNAME)$(HW)$(FOPTION) ./$(ROOTNAME)$(HW)$(FOPTION) $(RUNOPTIONS) please show how to run this program on linux
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started