added c skills excercise
This commit is contained in:
parent
e272d5f279
commit
101d087c79
5 changed files with 84 additions and 0 deletions
18
session1/c_skills/Makefile
Normal file
18
session1/c_skills/Makefile
Normal file
|
@ -0,0 +1,18 @@
|
|||
TARGETS = ass1 ass2
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -g
|
||||
|
||||
ifdef DEFINES
|
||||
CFLAGS += -D$(DEFINES)
|
||||
endif
|
||||
|
||||
all: $(TARGETS) Makefile
|
||||
clean:
|
||||
rm -f $(TARGETS)
|
||||
rm -f *.o *.~
|
||||
|
||||
ass1: ass1.o
|
||||
ass2: ass2.o
|
||||
|
||||
.PHONY: all clean
|
BIN
session1/c_skills/ass1
Executable file
BIN
session1/c_skills/ass1
Executable file
Binary file not shown.
31
session1/c_skills/ass1.c
Normal file
31
session1/c_skills/ass1.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <stdio.h>
|
||||
|
||||
struct route {
|
||||
int routeID;
|
||||
char descrp[25];
|
||||
};
|
||||
|
||||
typedef struct route Route;
|
||||
|
||||
|
||||
int main(int argc , char *argv[])
|
||||
{
|
||||
Route route1;
|
||||
struct route longroutes[10];
|
||||
struct route * routePtr;
|
||||
|
||||
printf("route id = ");
|
||||
scanf("%d", &route1.routeID);
|
||||
|
||||
printf("route descrip = ");
|
||||
scanf("%24s", route1.descrp);
|
||||
|
||||
longroutes[2] = route1;
|
||||
routePtr = longroutes;
|
||||
|
||||
printf("route id = %d, route descrip = %s\n",
|
||||
(routePtr+2)->routeID,
|
||||
(routePtr+2)->descrp);
|
||||
|
||||
return 0;
|
||||
}
|
BIN
session1/c_skills/ass2
Executable file
BIN
session1/c_skills/ass2
Executable file
Binary file not shown.
35
session1/c_skills/ass2.c
Normal file
35
session1/c_skills/ass2.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
double taxrate = 7.3, discountrate;
|
||||
char buyer[100], seller[100];
|
||||
|
||||
double * tmpPtr = &taxrate;
|
||||
|
||||
printf("*tmpPtr = %f\n", *tmpPtr);
|
||||
|
||||
discountrate = *tmpPtr;
|
||||
|
||||
printf("discountrate = %.2f\n", discountrate);
|
||||
|
||||
printf("&taxrate = %p\n", &taxrate);
|
||||
|
||||
printf("tmpPtr = %p\n", tmpPtr);
|
||||
|
||||
printf("equal? => %s\n", tmpPtr == &taxrate ? "yes" : "no");
|
||||
|
||||
strncpy(buyer, "Hello World!", sizeof(buyer));
|
||||
|
||||
strncpy(seller, buyer, sizeof(seller));
|
||||
|
||||
printf("buyer == seller? => %s\n",
|
||||
!strcmp(buyer, seller) ? "yes" : "no");
|
||||
|
||||
strncat(buyer, seller, sizeof(buyer));
|
||||
|
||||
printf("strlen(buyer) = %u\n", strlen(buyer));
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue