473,404 Members | 2,114 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,404 software developers and data experts.

Comparing for duplicate names

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <conio.h>
  5. #include <ctype.h>
  6. #include <ctype.h>
  7. #include <time.h>
  8. #include <sys/types.h>
  9.  
  10.  
  11.  
  12. int main ( void )
  13. {
  14. static const char filename[] = "1.txt";
  15. FILE *file = fopen ( filename, "r" );
  16. int i, j;
  17. char arra[128][128];
  18. char line[128];
  19. int result;
  20.  
  21. for(i=0; i<128; i++)
  22. for(j=0; j<128; j++)
  23. arra[i][j] = '\0';
  24.  
  25. for(i=0; i<128; i++)
  26. line[i] = '\0';
  27.  
  28. if ( file != NULL )
  29. {
  30.  
  31. i=0;
  32.  
  33. while ( fgets ( line, sizeof line, file ) != NULL )
  34.  
  35. {
  36.  
  37. strcpy(arra[i], line);
  38.  
  39.  
  40. printf("array ----> %s ", &arra[i]);
  41. i++;
  42.  
  43.  
  44.  
  45. }
  46. fclose ( file );
  47. }
  48. else
  49. {
  50. perror ( filename );
  51. }
  52.  
  53.  
  54. return 0;
  55. }
  56.  
this is the coding to get values from the text file and store it in the array .... i want a little hep in this can any one help me out how to compare each and every line and remove duplicate from the text file .......... waiting for ur help thanxs in advance ..................


this code is working nice
think if input file has text
shankar
ravi
kumar
kan
ravi

the output i will get has

array -> shankar
array ->ravi
array ->kumar
array ->kan
array ->ravi


c in the above output the name ravi has been repeated 2times .is that there is any possiblitly to remove the duplicate from the list above ....... and same way explain me how the values are stored in array .plz...........
Feb 7 '08 #1
5 2329
gpraghuram
1,275 Expert 1GB
If you want to search for duplicates in the array then you have to iterate for every element in the array and compare it with other values in the array.
If you can use C++ stl try to push the values to the set and you will end up having unique values

Raghuram
Feb 7 '08 #2
no i want to do in c program only and ......... really got struck here dont know to move further ........ and can u also explain me the code above .....
Feb 7 '08 #3
sicarie
4,677 Expert Mod 4TB
no i want to do in c program only and ......... really got struck here dont know to move further ........ and can u also explain me the code above .....
Did you not write the above code?
Feb 7 '08 #4
Did you not write the above code?


nooooooooooooooooo i did not write can any one explain me abt it
Feb 10 '08 #5
sicarie
4,677 Expert Mod 4TB
nooooooooooooooooo i did not write can any one explain me abt it
I would try to step through it logcially, and then put it into a compiler and user print statements to show the values of ALL the variables at different points (during loops, after loops, before loops, after function calls, etc...).

You should start there. After you understand what that code is doing, then you will know what you need to add to it.
Feb 10 '08 #6

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

Similar topics

44
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are...
7
by: Voetleuce en fênsievry | last post by:
Hello everyone. I'm not a JavaScript author myself, but I'm looking for a method to remove duplicate words from a piece of text. This text would presumably be pasted into a text box. I have,...
1
by: Adam Dockter | last post by:
I have a couple questions about comparing images. I notice the imagelist collection of images doesn't provide any comparison of images, and the System.Drawing.Image.Equal function will not compare...
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
8
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on...
5
by: rob | last post by:
Does anyone know of a duplicate file checker project in C#? Couldn't locate anything on CodeProject or SourceForge. Has anyone here considered writing one?
4
by: | last post by:
Given an XML file (dataset.writexml), here is my output (simplified for this posting): <?xml version="1.0" standalone="yes"?> <NewDataSet> <Category> <CategoryId>80</CategoryId>...
2
by: ChrisEdgemon | last post by:
I've got a set with contents like: I've got another set with contents like And another set with contents like I'd like to be able to compare set 1 with set 2 and have it match filename1 and...
5
by: Brett Barry: Go Get Geek! | last post by:
Hello, Can someone please paste VBA code and how I would go about doing this?: I have a customer table with over 6000 duplicates in the field called "Customer". While the customer names may...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.