The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[sh] String comparison operators userix Shell Programming and Scripting 1 05-16-2008 01:09 AM
string comparison Jatsui Shell Programming and Scripting 5 02-04-2008 12:28 PM
string comparison fedora Shell Programming and Scripting 2 01-03-2007 11:20 AM
String Comparison between two files using awk rudoraj Shell Programming and Scripting 7 07-25-2006 08:04 AM
string comparison operators, what are they?? ballazrus Shell Programming and Scripting 11 02-13-2006 03:30 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-19-2005
Registered User
 

Join Date: Sep 2005
Posts: 27
Stumble this Post!
String Comparison

Hi all,

I have a file like this

ibhib=ere
wefwfl=werfe
sfdes=wef

From this file, i need to get the lefthand side string with respect to the corresponding righthand side string. i.e, I need to get the string "ere" with respect to "ibhib".

But i am stuck with how to compare a string from a file. using getc can get the lefthand side string in an array(But how)?? Any help wil b greatly appreciated...


abey
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-19-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,849
Stumble this Post!
Code:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
/* this reads files up to twenty lines in length.*/
#define LINES_IN_FILE 20
#define DELIMITER "="

int main(int argc, char *argv[])
{
	FILE *in=fopen("myfile","r");
	char tmp[128]={0x0};
	char left[LINES_IN_FILE][64]={0x0};
	char right[LINES_IN_FILE][64]={0x0};
	int linecount=0;
	char *p=NULL;
	int i=0;

	while(fgets(tmp,sizeof(tmp), in)!=NULL)
	{
		p=strchr(tmp,(int) '\n');
		if(p!=NULL) *p=0x0;
		p=strtok(tmp,DELIMITER);
		if(p!=NULL)
		{
		  strcpy(left[linecount],p);
		  p=strtok('\0',DELIMITER);
		  strcpy(right[linecount++], p);
		}
	}
	fclose(in);
	for(i=0;i<linecount;i++)
	{
		printf("left value is:%s and the matching right value is:%s\n", 
		    left[i],right[i]);
	}
	return 0;
}
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:33 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0