Question: mt check is keep faild can some one help me please #include #include #include #include assignment 2 . h #define BLOCK _ SIZE 2

mt check is keep faild can some one help me please #include
#include
#include
#include "assignment2.h"
#define BLOCK_SIZE 256// Define the block size for buffer
int main(int argc, char *argv[]){
// Check if command-line arguments are provided correctly
if (argc <4){
printf("Usage: %s
", argv[0]);
return 1;
}
// Allocate memory for the personalInfo structure
personalInfo *pi =(personalInfo *)malloc(sizeof(personalInfo));
if (pi == NULL){
printf("Error: Memory allocation failed
");
return 1;
}
// Allocate memory for first name and last name
pi->firstName =(char *)malloc(strlen(argv[1])+1);
pi->lastName =(char *)malloc(strlen(argv[2])+1);
if (pi->firstName == NULL || pi->lastName == NULL){
printf("Error: Memory allocation failed
");
free(pi->firstName);
free(pi->lastName);
free(pi);
return 1;
}
// Populate the firstName and lastName fields
strcpy(pi->firstName, argv[1]);
strcpy(pi->lastName, argv[2]);
// Assign student ID (replace 123456789 with your actual student ID)
pi->studentID =123456789;
// Populate the level field (you can choose appropriate value based on your level)
pi->level = SENIOR;
// Populate the languages field (include at least three languages)
pi->languages = KNOWLEDGE_OF_C | KNOWLEDGE_OF_PYTHON | KNOWLEDGE_OF_JAVA;
// Copy the message from the third command-line argument
strncpy(pi->message, argv[3], sizeof(pi->message)-1);
pi->message[sizeof(pi->message)-1]='\0'; // Ensure null-termination
// Write personal information
if (writePersonalInfo(pi)!=0){
printf("Error: Writing personal information failed
");
free(pi->firstName);
free(pi->lastName);
free(pi);
return 1;
}
// Retrieve C strings and copy them into buffer
const char *str;
while ((str = getNext())!= NULL){
// Allocate memory for buffer
char *buffer =(char *)malloc(BLOCK_SIZE);
if (buffer == NULL){
printf("Error: Memory allocation failed
");
free(pi->firstName);
free(pi->lastName);
free(pi);
return 1;
}
// Copy data into buffer using memcpy
size_t len = strlen(str);
size_t copied =0;
while (copied < len){
size_t to_copy =(len - copied < BLOCK_SIZE)?(len - copied) : BLOCK_SIZE;
memcpy(buffer, str + copied, to_copy);
copied += to_copy;
// Commit the buffer
commitBlock(buffer);
}
}
// Call checkIt function
int result = checkIt();
// Free the allocated memory
free(pi->firstName);
free(pi->lastName);
free(pi);
return result;
} Assignment2.h file is below ypedef struct personalInfo
{
char * firstName;
char * lastName;
int studentID;
enum gradelevel {FRESHMAN=17, 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
#else
#error Do Not include header file assignment2.h more than once
#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!