![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
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;
}
|
|||
| Google The UNIX and Linux Forums |