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 );
}
}
}
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... ?
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.
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).