Hi guys
I'm having trouble with the code below.
I know strchr and strrchr both take int's as the second argument but I don't know how to make it work the way I want.
With strrchr I manually pass '/' as the second argument and it works.
I've tried different int's & chars using typecasting but I can't make it work by passing a variable. I don't know why it takes an int when likely we are going to be searching for some chars?
Here is the current code and error I get.
Thanks so much for your help guys!
lastoccurrence.c: In function `main':
lastoccurrence.c:29: warning: passing arg 2 of `strchr' makes integer from pointer without a cast
Code:
int main(int argc, char *argv[])
{
char stringsearch[900];
char *stringtosearch[900];
char *result;
/*printf("Argc=%d\n",argc);*/
if( argc != 2 )
{
printf("WTF: You need to enter 1 arguments: The string to search in\n");
return 39798;
}
strcpy(stringsearch,argv[1]);
/*
printf("String To Search=%s\n",stringtosearch);
printf("ARG1 (string to search)=%s\n",stringsearch);
*/
result=strrchr(stringsearch,'/');
result=strchr(stringsearch,result);
printf("%s\n",result);
return 0;
}