move exercises and lectures into subfolders
This commit is contained in:
37
Lectures/LC21/Cond/cond.c
Normal file
37
Lectures/LC21/Cond/cond.c
Normal 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;
|
||||
|
||||
}
|
24
Lectures/LC21/GetThem/getthem.c
Normal file
24
Lectures/LC21/GetThem/getthem.c
Normal 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;
|
||||
}
|
19
Lectures/LC21/Simple/simple.c
Normal file
19
Lectures/LC21/Simple/simple.c
Normal 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;
|
||||
}
|
||||
|
23
Lectures/LC21/Sprints/sprints.c
Normal file
23
Lectures/LC21/Sprints/sprints.c
Normal 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
29
Lectures/LC21/use.c
Normal 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;
|
||||
|
||||
}
|
Reference in New Issue
Block a user