Discuss the good, the bad and the ugly aspects of their code.
Please be gentle in any criticism - we are all learning!
Do you have any questions? Have you learned anything that would be useful to share with the rest of the tutorial?
Discuss why these are extremely dangerous, one of the worst causes of bugs in C programs and a major source of security vulnerabilities.
What does dcc --leak-check do?
struct node *list_append(struct node *list1, struct node *list2);As usual, struct node has this definition:
struct node { struct node *next; int data; };It should not create (malloc) any new list elements.
It should just change the appropriate next field in the first list.
struct node *strings_to_list(int len, char *strings[]);Assume the strings contain only digit characters,
It might be called like this:
char *powers[] = {"2", "4", "8", 16"}; struct node *head = strings_to_list(4, powers);
Assume, a command line argument of "-" separates the arguments to be converted.
struct node *merge_sorted(struct node *list1, struct node *list2);
It should not create (malloc) any list elements. It should change the appropriate next fields to combined the lists.
Implement this function both iteratively (using a while/for loop) and recursively.
Your tutor may still choose to cover some of the questions time permitting.
struct node *insert_ordered(int item, struct node *list);It should create (malloc) just 1 list element and change the appropriate next field in the list to insert it.
Implement this function.
double ff[] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6}; double *fp = &ff[0];
What are the similarities between ff
and fp
? What are
the differences?
char s[] = "Hello World!"; char *cp = s; char *cp2 = &s[8];
What is the output when the following statements are executed?
printf("%s\n", cp); printf("%c\n", *cp); printf("%c\n", cp[6]); printf("%s\n",cp2); printf("%c\n",*cp2);
fines.txt
this format:
Linus Torvalds fined $98 for not attending lectures. Denis Ritchie fined $50 for eating in labs. Ken Thompson fined $150 for attending lecture in his underpants.Write a program
student_fine.c
which reads this file and prints the student with biggest
fine including the amount and reason in this format.
a.out Biggest fine was $150 given to Ken Thompson for 'attending lecture in his underpants'.
int non_decreasing(int n, int a[n])which checks whether items in an array are sorted in non-decreasing order. (i.e. a[i] ≥ a[i-1], for 0<i<N). Your function should returns 1 if the items are in non-decreasing order, 0 otherwise.
int find_index(int x, int n, int a[n])which takes two integers x and n together with an array a[] of n integers and searches for the specified value within the array. Your function should return the smallest index k such that a[k] is equal to x (or -1 if x does not occur in the array).
c
in the
string s.
It returns NULL if the character cannot be found.
char *strrchr(char s[], char c)
Use this function from the math.h library:
double fabs(double x);
multiply.c
that performs addition or multiplication of integers, as follows.
Your program should continually read integers from the user until end-of-input
is encountered. Then it should print either the sum or the product of the input
numbers. The program behaviour is controlled by either of the following
command-line arguments:
-add, -multiply
. If the wrong command-line
argument(s) are supplied your program should do nothing.