Click here to Skip to main content
15,887,346 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
No.,Name,ID card,Pin code,Deposit,Date
1,Bilal Khan,1111111111111,1122,100,11-10-2020
2,Ali Ahmed,2222222222222,6677,100,11-10-2020
3,Bilal Khan,1111111111111,1122,50,11-10-2020
4,John,3333333333333,1122,50,11-10-2020
5,Bilal Khan,1111111111111,1122,70,11-10-2020
6,Ali Ahmed,2222222222222,6677,250,11-10-2020

**Required output**

No.,Name,ID card,Pin code,Deposit,Date
1,Bilal Khan,1111111111111,1122,100,11-10-2020
5,Bilal Khan,1111111111111,1122,70,11-10-2020
3,Bilal Khan,1111111111111,1122,50,11-10-2020
2,Ali Ahmed,2222222222222,6677,100,11-10-2020
6,Ali Ahmed,2222222222222,6677,250,11-10-2020
4,John,3333333333333,1122,50,11-10-2020

What I have tried:

I write data to the CSV file in C. The data are written in a random way but I want to arrange them. I don't want to be specific about them that to arrange this account first or that account second 

but I just want to arrange the data of one account *like* number one, three, and five are the same accounts but they are not arranged. Same with number two and six. They are the same accounts but not arranged and combined. So how to do this in C?
Posted
Updated 10-Oct-20 22:05pm

1 solution

That's going to depend on how you organise them when you read them from your file.
What I'd do is create a struct which contains all the info for a row:
typedef struct _Row
    {
    int No;
    char* name;
    char* IDCard;
    int PinCode;
    float Deposit;
    time_t Date;
    } Row;
Then fill an array with those.
Then you can use the qsort function[^] to order them by whatever you like ...
 
Share this answer
 
Comments
ibilalkayy 11-Oct-20 5:22am    
I'm not reading. I am trying to write data in the file but in an arranged way
OriginalGriff 11-Oct-20 5:50am    
It's a text based file - CSV is always text - so the only way to write it in an ordered manner is to order it before you write it!

Text files don't support "insert" or "delete" operations, so you can't sort it in the file itself.
ibilalkayy 11-Oct-20 6:32am    
How to order it before writing?
OriginalGriff 11-Oct-20 6:34am    
Read what I said to start with?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900