Would you please help me in writing a c code to read data from a file and perform 1)numeric sort, 2)alphabetical sort.
the file may contain data of any kind.Like it may contain only numbers,only names or a database of employees of a company.(which contains their employee id,name,designation and salary,....in different fields).Each line contains details of one employee.
Sorting has to be done based on field specified.i.e,if sorting has to be done considering 3rd field(designation),
alphabetical sort has to be performed.And if the specified field contains information other than name or designation numeric sort has to be performed.
I would prefer a c program to solve the above problem.
Recommended Answers
Jump to Postyou make struct Employee has(id ,name,salary,....) and make every Employee as node in linked list
then
save linked list into file after fill some datathen
read data from file and you can sort data by bubble sort :
(if you need numeric sort then sort nodes by id )
…
Jump to Postdata for one Employee you need read from file ,has already in file or not?
Jump to PostThe logic for sorting with string keys is no different than with numeric keys. The only difference is in the comparison, where with string keys you cannot use relational operators. Instead, compare with strcmp():
if (strcmp(a->name, b->name) < 0) { /* a->name is lexicographically smaller than b->name …
All 11 Replies
ahmedhamdy
0
Light Poster
ahmedhamdy
0
Light Poster
priyanka raj
0
Newbie Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
ahmedhamdy
0
Light Poster
ahmedhamdy
0
Light Poster
ahmedhamdy
0
Light Poster
ahmedhamdy
0
Light Poster
priyanka raj
0
Newbie Poster
priyanka raj
0
Newbie Poster
aaaymen
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.