Char Array...

How to check if in linked list char array is equal to another char array in list?

Example...
struct list{
char name[15];
list *next;
}

User write names in list...how to check if user write 2 equal names?

1
2
3
4
if (!(strcmp(array1, array2))
{
   // they are the same length with the same contents
}
I know for strcmp but what algoritam can i use to sort alphabetical names in linked list?
There are many sorting algorithms.

Here's a very simple one (it's rubbish, but simple).

1
2
3
4
5
Look at first two names in list. 
  If in wrong alphabetical order, swap them around. Start again.
  If not in wrong alphabetical order, move on to names 2 and 3.
    If in wrong alphabetical order, swap them around. Start again.
    If not in wrong alphabetical order, move on to names 3 and 4.

And so on. You can easily do better than this algorithm given a few minutes thought.

The bigger picture here is that you've started to get into actual programming. All that stuff about learning the language isn't programming. It's just learning the language. Programming is the art, craft and science of thinking about problems in such a way that the solution lends itself to a programmatic solution. If you need to rearrange the list into alphabetical order, you're going to have to think. Honestly, there's no trick to it. Just think about it.
Last edited on
Ok...Thanks...My problem actualy is to find number of equal char arrays...And i think that easiest is to first sort and then compare...
Topic archived. No new replies allowed.