Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this step, you need to move the functions printElement and initElement to a s

ID: 3823205 • Letter: I

Question

In this step, you need to move the functions printElement and initElement to a separate source file: Create a header file elementops.h. Protect it using the #ifndef macro definition. Add the struct typedef definition to elementops.h Add the prototype of the functions printElement and initElement to it. Create the corresponding elementops.c and add the function definitions to it Modify your main program to use the declarations of elementops.h and remove the duplicate definitions from elements c To compile your program, you can use the following command: gcc -o elements elements. c elementops.c

Explanation / Answer

//Multiple Files:

//Elementops.h save as separate file

#ifndef ELEMENTOPS_H_INCLUDED

#define ELEMENTOPS_H_INCLUDED

typedef struct element1{

int arr[10];

} ele;

void initElement(int arr[]);

void printElement(int arr[]);

#endif // ELEMENTOPS_H_INCLUDED

//Elementops.c

#include <stdio.h>

#include "elementops.h"

#include "element.h"

void printElement(int arr[])

{

printf("The array of elements are: ");

for(int i=0;i<10;i++){

printf(" %d",arr[i]);

}

}

void initElement(int arr[])

{

arr[0]=12;

arr[1] =45;

arr[2]=34;

arr[3]=97;

arr[4]=32;

arr[5]=46;

arr[6]=21;

arr[7]=48;

arr[8]=2;

arr[9]=05;

}

//Element.c

#include <stdio.h>

#include "elementops.h"

void main()

{

ele arr;

initElement(&arr);

printElement(&arr);

}

output:

The array of elements are:

12

45

34

97

32

46

21

48

2

5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote