473,473 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

My first quistion

1 New Member
Hi every body..
I've corrected my code in which I would like to compare strings of two txt files;

file1.txt=
054,8100,171
054,8100,191


file2.txt=
054,8100,171
054,8100,191
054,8100,171
054,8100,181
054,8100,171
054,8100,171
054,8100,171

to be as following:

Code:
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<conio.h>
  5.  
  6. void pError(char * s){
  7.    printf("%s\n",s);
  8. }
  9.  
  10. int main(){
  11.  
  12. int equal_lines=0;
  13. FILE *pt1,*pt2;
  14. pt1=fopen("file1.txt","r");
  15. if (pt1==NULL)
  16.    pError("open error f1");
  17. pt2=fopen("file2.txt","r");
  18. if (pt2==NULL)
  19.    pError("open error f2");
  20.  
  21. short q=0;
  22. char c1[50],c2[50]; //declaring a string to hold the content of each file.
  23. int buf_size=sizeof(c1);
  24.  
  25. fgets(c1,buf_size,pt1);
  26. while(((fgets(c2,buf_size,pt2))!= NULL)&&(!q))
  27.    {
  28.         printf("f1: %s\n",c1);
  29.         printf("f2: %s\n",c2);
  30.  
  31.  
  32.          if(strcmp(c1,c2)==0)
  33.            equal_lines++;
  34.  
  35.  
  36.    }
  37.  
  38. printf("\n\n equal_lines=%d",equal_lines);
  39. getch();
  40. return 0;
  41. }
untill this point, it's perfectly achieve comparing 1st string of file1 with all strings of file2...
but know, I want to compare the 2nd string of file1 with all string of file2.. and so on consecutively..

I would greatly appreciate it if I could get some assistance! Thanks in advance!
Feb 22 '10 #1
1 1230
Banfa
9,065 Recognized Expert Moderator Expert
Just before/at/instead of line 25 you need a loop similar to line 26 that operates on file 1.
Feb 22 '10 #2

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

Similar topics

24
by: Hung Jung Lu | last post by:
Hi, Does anybody know where this term comes from? "First-class object" means "something passable as an argument in a function call", but I fail to see the connection with "object class" or...
12
by: Alan J. Flavell | last post by:
OK, today's email brought a comment from a reader, pointing out something that I'd long since noticed myself but hadn't done anything about it. On my pages, I've got a first-letter style on...
1
by: Patrick | last post by:
I am trying to get "first-letter" to work inline withing an anchor. Actually I have not been able to get it to work within an <a> tag whether inline, linked, or embedded. Using IE6 service pack 1....
3
by: Chris Tanger | last post by:
I am creating a class that has a method "Write" that I wish to make threadsafe. The method must block calling threads until the task performed in write is complete. Only 1 thread at a time can...
4
by: KJ | last post by:
We use a third party software package for acctg that limits us on field size - as a result, we at times have to enter an item into the app multiple times in order to get all the information. I...
43
by: Roger L. Cauvin | last post by:
Say I have some string that begins with an arbitrary sequence of characters and then alternates repeating the letters 'a' and 'b' any number of times, e.g. "xyz123aaabbaabbbbababbbbaaabb" I'm...
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
HI I have a stored procedure that returns data with a date field in the form of a DateTime type. I need to place data in variables based on days of the week starting with the first thursday of the...
4
by: Milan Krejci | last post by:
int first=15,latest=15; QString typ=NULL; std::map<int,std::string>::iterator i; for(i = SeznamPracovniDoby.begin(); i != SeznamPracovniDoby.end(); i++) { if (typ==NULL) typ=i->second.c_str(); if...
3
by: cs | last post by:
Hi, I'm new to C and would appreciate any feedback on the following program, asplit, which splits a file into 2 new files, putting a certain number of lines in the first file, and all the rest...
3
by: dmalhotr2001 | last post by:
Hi, For string extraction function in vb, if I feed in a paragraph, how do I extract the first sentence of that paragraph. Thanks :D
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.