473,322 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Related File Handeling in C lang.

Hi All,

I want to get some values by reading a file (already created) through file handeling but dont want to get DUPLICATE values.

How can i do that..plz help me out.......

E.g: file name input.txt having rows like:

Root 400
Bye 789
Teacher 123
Bye 789

in output i want to print only :
Root 400
Bye 789
Teacher 123

Note: Dont want to print duplicate data (Teacher 123)

If any idea..plz tell me ...with example too.

--
Sharique
Jul 10 '08 #1
9 2258
gpraghuram
1,275 Expert 1GB
Option 1
You can use unix utilities instead of C code like this
cat input.txt | sort -u

Option 2
You have to read the data push it to a map or set and then print the map.
If you can use C++

Option 3
You have to write a adata structure which will store uniqe values.


Raghu
Jul 10 '08 #2
Hi Raghu,

I have to use only C file handeling...i cant change this.
Can u plz give me small example to select only distinct values from file which we ae opening thru file handeling...

if possible plz give me peice of prog.

Thanks,
Sharique

Option 1
You can use unix utilities instead of C code like this
cat input.txt | sort -u

Option 2
You have to read the data push it to a map or set and then print the map.
If you can use C++

Option 3
You have to write a adata structure which will store uniqe values.


Raghu
Jul 11 '08 #3
gpraghuram
1,275 Expert 1GB
If you have to use only C then write a hash list to store the values and before storing check whether the element exists and then store it.
First start writing the code and if u face issues i can help you out with the problem.
I cant write the code for you

Raghu
Jul 11 '08 #4
Hi Rahgu,

I have written this code:

::Full code removed, please read Posting Guidelines::

in that code, how can i avoid duplicate values? i m not aware abt hash list and i have checked with my team mate....i can use only simple file hadeling.

please help me on this...

--
Sharique

If you have to use only C then write a hash list to store the values and before storing check whether the element exists and then store it.
First start writing the code and if u face issues i can help you out with the problem.
I cant write the code for you

Raghu
Jul 11 '08 #5
can any one help me on this?
Jul 14 '08 #6
Hi Rahgu,

I have written this code:

::Full code removed, please read Posting Guidelines::

in that code, how can i avoid duplicate values? i m not aware abt hash list and i have checked with my team mate....i can use only simple file hadeling.

please help me on this...

--
Sharique




If you have to use only C then write a hash list to store the values and before storing check whether the element exists and then store it.
First start writing the code and if u face issues i can help you out with the problem.
I cant write the code for you

Raghu
Jul 14 '08 #7
gpraghuram
1,275 Expert 1GB
This is OK.
But withoput using a data structure you cant get the sorted vales from a file.
Check whether u can use an array....

Raghu
Jul 14 '08 #8
Hi Raghu,

But can we avoid duplicates values ( when we are reading from file )??
after reading values from file, we can put in array or in stuct.

----
Sharique

This is OK.
But withoput using a data structure you cant get the sorted vales from a file.
Check whether u can use an array....

Raghu
Jul 14 '08 #9
gpraghuram
1,275 Expert 1GB
It is not possible to avoid duplicate values while reading.


Raghu
Jul 16 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marc Cromme | last post by:
I would like to ask a question about (good ?) style and possibilities in mixing C FILE* and C++ file streams. The background is that I want to use the C libpng library from within C++, but I...
18
by: Manohar S | last post by:
It is a problem related to printf, and buffering to the printf statements Look through this program. main() { int pid; int loop,max=3; for(loop = 0; loop <max;loop++) { pid = fork();
4
by: velvetyuan | last post by:
I'm not sure whether it is proper to post it here, but I regard it at least has something to do with C++. Let me try to clarify my problem: I have two files: triangle.h, triagle.c I compiled...
3
by: Kbalz | last post by:
I have a Form that is performing a wizard-like step system (using TabControl), and I need a key combination (like ControlKey + A + T) to be caught and show a secret admin TabPage. I tried to add...
1
tolkienarda
by: tolkienarda | last post by:
hello wonderful people of java land i am writing a program and trying to check to make sure some of my inputs are valid integers. i was told that i needed to read into exception handeling and now...
1
by: ashruba | last post by:
I want to read inbox of nokia N72 through file handeling in c/c++ please give guidence.
11
by: whirlwindkevin | last post by:
I saw a program source code in which a variable is defined in a header file and that header file is included in 2 different C files.When i compile and link the files no error is being thrown.How is...
4
by: shariquehabib | last post by:
Hi All, I am using file handeling in C lang. Can anyone please let me know that how can i read spaces from a perticular file?? To read some values (strings) i m using fscanf func. Can...
2
by: shariquehabib | last post by:
Hi, I am using C language to read a file: row.txt Can any one plz help me to get number of rows present in a file BEFORE reading a file. So i can check number of rows and if the rows greater...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.