Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

C Programming

Rating
-
Sold
-
Pages
2
Uploaded on
19-10-2023
Written in
2022/2023

"C Programming Notes for GATE CSE" serves as a valuable resource for students preparing for the Graduate Aptitude Test in Engineering (GATE) in the field of Computer Science and Engineering. These comprehensive notes cover the essential aspects of the C programming language, a fundamental tool for computer science professionals. With a focus on key topics and concepts, this resource aids in understanding the intricacies of C programming, which is crucial for success in the competitive GATE examination. Whether you're a GATE aspirant or simply seeking to enhance your knowledge of C programming, these notes provide a clear and concise guide to help you grasp the language's principles, making them a valuable asset for your academic and professional journey.

Show more Read less
Institution
Course

Content preview

Massachusetts Institute of Technology
Department of Electrical Engineering and Computer Science

6.087: Practical Programming in C

IAP 2010

Problem Set 6
Part 2: Function pointers, hash table

Out: Thursday, January 21, 2010. Due: Friday, January 22, 2010.


Problem 6.1
In this problem, we will use and create function that utilize function pointers. The file ’call­
back.c’ contains an array of records consisting of a fictitious class of celebrities. Each record consists
of the firstname, lastname and age of the student. Write code to do the following:

• Sort the records based on first name. To achieve this, you will be using the qsort() function
provided by the standard library: void qsort(void∗ arr,int num,int size,int (∗fp)(void∗ pa,void∗pb)).
The function takes a pointer to the start of the array ’arr’, the number of elements ’num’ and
size of each element. In addition it takes a function pointer ’fp’ that takes two arguments.
The function fp is used to compare two elements within the array. Similar to strcmp(), it
is required to return a negative quantity,zero or a positive quantity dependeing on whether
element pointed to by ’pa’ is ”less” than, equal to or ”greater” the element pointed to by
’pb’. You are required to write the appropriate callback function.

• Now sort the records based on last name. Write the appropriate callback function.

• The function void apply (...) iterates through the elements of the array calling a function for
each element of the array. Write a function isolder() that prints the record if the age of
the student is greater 20 and does nothing otherwise.

Problem 6.2
A useful data structure for doing lookups is a hash table. In this problem, you will be imple­
menting a hash table with chaining to store the frequency of words in a file. The hash table is
implemented as an array of linked lists. The hash function specifies the index of the linked list to
follow for a given word. The word can be found by following this linked list. Optionally, the word
can be appended to this linked list. You will require the code file ’hash.c’ and data file ’book.txt’
for this problem. You are required to do the following

• The function lookup() returns a pointer to the record having the required string. If not
found it returns NULL or optionally creates a new record at the correct location. Please
complete the rest of the code.

• Complete the function cleartable() to reclaim memory. Make sure each call to malloc()
is matched with a free()




1

Written for

Course

Document information

Uploaded on
October 19, 2023
Number of pages
2
Written in
2022/2023
Type
Class notes
Professor(s)
Daniel weller
Contains
All classes

Subjects

$49.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
shubhjaiswal

Get to know the seller

Seller avatar
shubhjaiswal Teachme2-tutor
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
48
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions