hope all r doing fine..
i need a quick and very quick reply
m porting some cod e from windows to linux box..n i just encountered a function findfirstfile() used in windows..this function also takes wildcards as regular expression in the string
I searched the net for an alternate implementation in linux but hadnt got any! so m asking u guys tht if u have any idea or if someone has coded this function in linux then plz let me know... u can search findfirstfile() detail in MSDN
yes i have used those functions but the problem is that I couldnt find any builtin function in linux that can accept regular expressions as well... the windows function finddirstfile() accepts regular expression like "file*.txt", "?a*.c" ... i can use the linux functions for simple find first search by using dirent but i need to search in dirent structure with regular expression support as well... i want to know if there is any prebuilt function that at least searches with regular expression bcoz i dont want to write this function by myself if there exists any already.
thnx guys ... 'm near to end this..
infact i wasnt aware of regex b4 as i never needed it so 'm new to this..
i just wrote this code to test regex.h
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <regex.h>
int main(int argc,char **argv)
{
char str[20]="iamnabil";
int status;
regex_t myre;
regcomp(&myre, argv[1], REG_EXTENDED|REG_NOSUB);
status = regexec(&myre, str, (size_t)0, NULL, 0);
if(err==REG_NOMATCH)
printf("\n nOT matcheD\n");
else
if(err==0) printf("\nMatcHed !\n");
return 0;
}
it is working great but when i give * or ? wildcards at start of my RE string..it complains for segmentation fault..
like if i give expression as "*nabil" or "?am*" then segmentation error is caused then
can any1 help me here now and fix this...
it is working great but when i give * or ? wildcards at start of my RE string..it complains for segmentation fault..
like if i give expression as "*nabil" or "?am*" then segmentation error is caused then
can any1 help me here now and fix this...
Bear in mind that if you type in ./myprog *nabil at most Linux/Unix prompts, then the default is for the shell to have a go at expanding the wildcard expression to begin with. If that fails, then it's likely that your program will see argv[1] as being NULL, and that's where your segfault is coming from.
Perhaps check argc / argv before trying to use them in your code.
In bash, you can modify the shell's wildcard expansion, to allow such expressions to be passed to your program.
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.