sesh48
2008-09-22 14:23:19 UTC
Everything below is supposed to be done with basic C commands only which is restricted to strings, arrays, loops such as for and if loops, and pointers and basic commands like that. I am really lost and would appreciate some code help.
1.
Create a new C function which will count the number of vowels (A, E, I, O or U, capital or lower case) in a string passed to it, and return that number (as an "int"). Note that the type of the string passed into this function should be "const char *" - as strings are really arrays of "char"s - which, in turn, are really constant pointers to "char"s).
Add to your main program several test calls to this function, and print out the strings passed in and the responses to the screen. Be sure to check any corner cases you can think of.
2.
Add another C function to your program which returns nothing (void), but takes two writable strings and compares them. If the first is alphabetically (see here) after the second, then your function should completely swap the contents of the two strings before returning. It is the caller's responsibility to be sure the memory the strings reside in is writable and that there is enough space in the array holding each to hold the other should they need to be swapped (and you should note these limitations in the comments for this function).
Note that this sort should NOT be case-sensitive (so neither "Ape" nor "ape" is alphabetically after the other). Non-letters should be entirely ignored and skipped (so neither "ape" or "432a--P. E++" is alphabetically after the other). Also, shorter words should be sorted before longer words which contain that entire shorter word at their beginning (so "fish" comes before "Fisher").
Add to your main program several tests of this, outputting the results of each.