move exercises and lectures into subfolders

This commit is contained in:
2023-10-15 15:34:53 +01:00
parent 775b4bd643
commit 74092a17aa
177 changed files with 0 additions and 0 deletions

37
Lectures/LC21/Cond/cond.c Normal file
View File

@@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
/* We define one thing - we need not give it a value, but we can */
#define BUILD1
int main(void)
{
printf ("\nThis code is common to all ");
/* We check for the existance ob 'BUILD1' and act accordingly */
#ifdef BUILD1
printf ("\nWe had BUILD1 defined ");
#else
printf ("\nBUILD1 was not defined ");
#endif
/* Can can see if somthing was not defined too */
#ifndef BUILD2
printf ("\nBUILD2 was *NOT* defined ");
#endif
printf ("\n\n");
return 0;
}

View File

@@ -0,0 +1,24 @@
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int age;
char name[10];
/* we check the argument count is 3 ( prog name plus 2 params ) */
if ( argc != 3 )
{
printf ("\nProgram use %s name age ",argv[0]);
exit (0);
}
/* Copy the command parameters into suitable variables */
sscanf(argv[1],"%s",name);
sscanf(argv[2],"%d",&age);
/* And display for all to see */
printf ("\nHello %s, you are %d ",name,age);
return 0;
}

View File

@@ -0,0 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
/* Note the new type of main */
int main(int argc, char *argv[])
{
int x;
/* Print the argument count */
printf("Arguments -> %d\n",argc);
/* And the arguments themselves */
for (x=0; x<argc; x++)
printf("%s\n",argv[x]);
return 0;
}

View File

@@ -0,0 +1,23 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
char buffer[100];
int age=6;
char name[6];
/* This command copies "James" into the character array 'Name' */
strcpy(name,"James");
/* Print to the string (rather than screen) */
sprintf(buffer,"Name: %s, Age %d ",name,age);
/* And output the string created */
printf("\n->%s\n",buffer);
return 0;
}

29
Lectures/LC21/use.c Normal file
View File

@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#define BUILD1 23
int main(void)
{
int MyValue = 0;
printf ("\nThis code is common to all ");
#ifdef BUILD1
printf ("\nWe had BUILD1 defined, will adjust value accordingly ");
MyValue = BUILD1;
#else
printf ("\nBUILD1 was not defined, leaving MyValue alone ");
#endif
printf ("\nThe value in MyValue is %d ",MyValue);
printf ("\n\n");
return 0;
}