I'm new to strings...

Nov 20, 2008 at 8:07pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
void sortWords(char wordList[][WORD_SIZE], int wordCounts[], int numWords)
{
  int i, j;
  int min, temp;
  char *k;


for (i = 0; i < numWords-1; i++)
  {
    min = i;
    for (j = i+1; j < numWords; j++)
    {
      if (strcmp(wordList[j], wordList[min]) < 0)
        min = j;
    }
    k = wordList[i];
    wordList[i] = wordList[min];
    wordList[min] = k;
    
	temp = wordCounts[i];
    wordCounts[i] = wordCounts[min];
    wordCounts[min] = temp;
  
  
  }
  
  
}


I'm getting problems in lines 16-18 about variable types. Can someone tell me what I'm not getting? It looks especially silly now, I think, because I was messing with it to try to get it to work just now.

Thanks to anyone who can help out.
Nov 20, 2008 at 9:14pm
Arrays and pointers in this case aren't the same thing. You are attempting to "copy" strings by swapping pointers.

lines 16-18 are all wrong. You have to memcpy() or strcpy().
Topic archived. No new replies allowed.