Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hopefully the last one #341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions AY 2022-2023/Student Works/ilijapetrov/finalProgram.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
structures(records)
functions and parameters
by value and by refrence (pointers)
*/
#include <stdio.h>

//define structure
struct agent
{
char cRole;
char sName[10];
int dID;
struct agent *a;
};

//function prototypes
void printAgentRef();
void printAgentVal();


int main(int argc, char const *argv[])
{

//local variables of struct agent
struct agent a1, a2, a3, a[100];

//we want the user to enter values for a1
printf("\nEnter agent name: ");
scanf("%s", a1.sName); //no &
printf("\n Enter the role of %s: ", a1.sName);
scanf(" %c", &a1.cRole);
printf("\n Enter ID of %s: ", a1.sName);
scanf("%d", &a1.dID);

printf("\nEnter agent name: ");
scanf("%s", a2.sName); //no &
printf("\n Enter the role of %s: ", a2.sName);
scanf(" %c", &a2.cRole);
printf("\n Enter ID of %s: ", a2.sName);
scanf("%d", &a2.dID);

//we are going to use pointers to connect a1 to a2
a1.a = &a2;


//print a1 using the externam function
printAgentRef(&a1); //use & to pass the adress of the struct
// printAgentVal(a1); //just duplicate no need for address
printAgentRef(a1.a);

return 0;
}//end of main

//function definitions
void printAgentRef(struct agent *a){
printf("\n Agent name: %s", a->sName);
printf("\n Agent role: %c", a->cRole);
printf("\n Agent ID: %d \n", a->dID);
}//endref



void printAgentVal(struct agent a){
printf("\n Agent name: %s", a.sName);
printf("\n Agent role: %c", a.cRole);
printf("\n Agent ID: %d \n", a.dID);
}//endval























19 changes: 19 additions & 0 deletions AY 2022-2023/Student Works/ilijapetrov/struct element{
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
struct element{
int val;
struct element *next
}

struct element e1, e2, e3 , e4, head, tail, temp

head.next=&e1;
e1.val= 420;
e1.next= &e2;
e2.val= 69;
e2.next= &e3;
e3.val= 27;
e3.next= NULL;
tail= e.next;

//so if i want to sort them
temp= &e1;
head.next= &e3;