I have a string called typedString in C and I need to order the words alphabetically. This code gives me an error of passing argument 1 of ‘strcmp’ makes pointer from integer without a cast expected ‘const char *’ but argument is of type ‘int’. warning: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast. How can i fix this it?
Code:
char typedString[300] = " this, is i and a test file, i repeat test file.";
int len = strlen(typedString);
char newString[len];
//int i;
for (i = 0; i < len; i++) {
newString[i] = '\0';
}
int newIndex = 0;
for (i = 0; i < len; i++) {
if (typedString[i] >= 'a' && typedString[i] <= 'z' || typedString[i] >= 'A'
&& typedString[i] <= 'Z' || typedString[i] == ' ') {
newString[newIndex] = typedString[i];
newIndex++;
}
}
char stringList[300][20];
char *pch;
pch = strtok(newString, " ,.-");
int totalWord = 0;
while (pch != NULL) {
strcpy(stringList[totalWord], pch);
pch = strtok(NULL, " ,.");
totalWord++;
}
int j;
char test1[20];
char test2[20];
for (i = 0; i < totalWord; i++) {
strcpy(test1, stringList[i]);
for (j = i + 1; j < totalWord; j++) {
strcpy(test2, stringList[j]);
if (strcmp(strlwr(test1), strlwr(test2)) > 0) {
char temp[20];
strcpy(temp, test1);
strcpy(test1, test2);
strcpy(test2, temp);
strcpy(temp, stringList[i]);
strcpy(stringList[i], stringList[j]);
strcpy(stringList[j], temp);
}
}
}
printf("\n\nSorted string is\n");
for (i = 0; i < totalWord; i++) {
printf("%s ", stringList[i]);
}