I'm not so familiar with functions and function prototypes. I get compiler errors which is the line where I attempt to pass the strings to a function
Type error in argument 1 to 'sort'; expected 'char *' but found 'char'
Type error in argument 2 to 'sort'; expected 'char *' but found 'char'
Type error in argument 3 to 'sort'; expected 'char *' but found 'char'
Type error in argument 4 to 'sort'; expected 'char *' but found 'char'
Code:#include <stdio.h> #include <string.h> void sort (char *,char *,char *,char *); int main() { char *str1 = {"Florida"}; char *str2 = {"Oregon"}; char *str3 = {"California"}; char *str4 = {"Georgia"}; printf("Four states in alphabetical order"); sort(*str1, *str2, *str3, *str4); } void sort (char *str1,char *str2, char *str3, char *str4) { if (strcmp(str3, str1) >0) printf("\n%s", str3); if (strcmp(str1, str4) >0) printf("\n%s", str1); if (strcmp(str4, str2) >0) printf("\n%s", str1); if (strcmp(str2, str4) <0) printf("\n%s\n", str1); } /* Build a program that uses an array of strings to store the following names: • “Florida” • “Oregon” • “California” • “Georgia” Using the preceding array of strings, write your own sort() function to display each state’s name in alphabetical order using the strcmp() function. */



LinkBack URL
About LinkBacks



