Complex string problems. :(

So, the ask:
"A file stores competition's participants information (eg: SURNAME/Country; VENUS/England). Find all surnames from England that are word-polindromes"

So, for example my file is str.dat, inside the file this text:

"VANAV/England VUNUV/England TEST/Usa"

How do I leave TEST/USA out? And could you please help me with code... im kinda lost(sorry for bad language im in a hurry!):

#include<stdio.h>
#include<conio.h>
#include<string.h>

int is_palindrome(char* w)
{

    int i;
    int j=(strlen(w)-1);
        for (i = 0, j; i < j; ++i, --j)
        {
            puts(w);
        }

     return 0;
    }


main()
{
    int p,i,min=100,l;
    FILE *in;
    char c[]="England",s[80],w[80], *temp, znak1[]="/England";
    in=fopen("str.dat","r");
    printf("palindromes:");
    while(fscanf(in,"%s",s)!=EOF)
    {
    temp=strtok(s,znak1);
    while( temp != NULL ) {
        
         strcmp (temp,znak1) ;
         puts(temp);
        
  
    temp = strtok( NULL, znak1 );
    }
}
}
 
if (s[0] == 'T' && s[1]=='E' && s[2]=='S' && s[3]=='T') continue;?
That's not an option as file will be filled with random country names. As in, Test/Wales; Test/Ireland; Test/Zimbabwe. As you can see, I have to get rid of "/England", if it doesn't contain it I should skip it (as in remove from new string, after that parsed to is_polindrome) ... I really have no clue what to do; should I use strcmp, if so what will it compare... ?
Last edited on
Well, strcmp() could be used to solve part of the problem. strchr() and strncpy() might also help, it you're not wanting to use std::string. See this site's help on the functions for details.

But it might be quicker to write a custom function, instead.

If you know what a palindrome is, then the solution should follow.
Last edited on
My problem is, I'm kind of new; they are killing us at university. I do not fully understand how strcmp works, and what should I compare inside of it, I know what a palindrome is, and how to solve this, though theoretically (not the solution I had listen above). What I do not know is how to get rid of "/England" and leave out surnames from other countries.

My questions are as followed:

Should I use strtok in the first place?;
If so how does it help me achieving my goal?;
What other functions should I use?;

Of course, somebody could post a ready solution for me, I would not complain. But if that is the case, I should understand what it is doing; thus no fancy tricks (as in something I would not understand).
Bump, I have to complete this by tomorrow.
_ Read one pair surname/country
_ Separate the pair. Use the slash
_ Check if the country is the one you want
___ Check if the surname is a palindrome
I know the algorithm, what I do not know is how to pull it off in C, or did not not, until recently. That said, I no longer need this thread. :p
Topic archived. No new replies allowed.