Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to print the team names ending with the word entered by the user.


What I have tried:

for (i=0;i<10;i++)
if (strncmp(teams[10-i],value,strlen(value))==0)
printf("%s\n",teams[i]);
Posted
Updated 3-Jul-20 19:47pm
v2
Comments

1 solution

I would generalise your code that you've started with
if (strncmp(takimAdi[10-i],deger,strlen(deger))==0)

to an 'ends_with' function. In doing so, you need to check that the length of the string you're checking, eg the 'bursaspor' is longer than the length of the 'ending' - so you would need to consider using 'strlen' as well.

Maybe, some of this looks like
int ends_with(const char * str, const char * ending)
{
  int str_len = strlen(str);
  int ending_len = strlen(ending);

  return 
    (str_len >= ending_len) &&
    // use strcmp here to check the 'end' of the str for 'ending'
}


So you need to replace // use strcmp here to check the 'end' of the str for 'ending' with some code, and you were heading in the right direction with what you had (if that helps)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900