![]() |
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 |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| finding string at runtime | inderpunj | Shell Programming and Scripting | 1 | 05-01-2008 03:19 AM |
| help with finding a string | sandyg | Shell Programming and Scripting | 2 | 09-28-2007 10:15 AM |
| Finding funny charaters in a string | ahjaeasedqa | UNIX for Dummies Questions & Answers | 4 | 04-02-2007 02:05 AM |
| Finding part of a string | DAFNIX | Shell Programming and Scripting | 4 | 09-20-2006 11:24 PM |
| Finding a certain string on each line in a file | VODAFUN | Shell Programming and Scripting | 5 | 10-07-2005 05:48 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
hi all..
I dont know how to search for a string in a file.. I have tried doing.. I did google but didnt get effective answers..my code is as follows: int search(char* filename,const char* username,const char* passwd) { int flag=0; unsigned long fsize=0; unsigned long current=0; int fdsearch=-1; int cun,cpw; char *user,*pass; int un,pw; pw=strlen(passwd); un=strlen(username); fdsearch=open(filename,O_RDONLY); fsize = lseek(fdsearch, 0L, 2); user=(char*)malloc(un); pass=(char*)malloc(pw); while (current<fsize) { lseek(fdsearch,current,SEEK_SET); cun=read(fdsearch,user,un); cpw=read(fdsearch,pass,pw); if(!memcmp(username,user,un)) { if(!memcmp(passwd,pass,pw)) { flag=1;//found close(fdsearch); return(flag); } printf("incorrect password"); close(fdsearch); return(flag); } //increment current position by 1 current++; }//while return flag; } I dont know how to read end of string(space will be the delimiter in the file),then end of line. i guess the bolded areas are where I am doing mistakes.. kindly help me... thanks in advance ![]() |
|
||||
|
Quote:
Thanks Nagarajan G |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|