![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| string comparison operators, what are they?? | ballazrus | Shell Programming and Scripting | 12 | 04-07-2009 11:43 AM |
| [sh] String comparison operators | userix | Shell Programming and Scripting | 1 | 05-16-2008 04:09 AM |
| string comparison | Jatsui | Shell Programming and Scripting | 5 | 02-04-2008 04:28 PM |
| string comparison | fedora | Shell Programming and Scripting | 2 | 01-03-2007 03:20 PM |
| String Comparison between two files using awk | rudoraj | Shell Programming and Scripting | 7 | 07-25-2006 11:04 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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 |
|
||||
|
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;
}
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|