Question:
I've a question about Programming in the language C..?
sesh48
2008-09-22 14:23:19 UTC
I am trying to write a basic program in C and as I am a beginner I could use some help. I need to learn this material fast and I'm having a lot of trouble. If someone could help me out with the following that'd be great.
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.
Three answers:
Mike R
2008-09-22 14:29:12 UTC
I'd love to help you but posting your homework is a bad idea. Asking for general help or tutorials will help you out a lot more.

That being said, here's a tutorial for you: http://www.physics.drexel.edu/students/courses/Comp_Phys/General/C_basics/
tice
2016-09-07 10:56:06 UTC
There is not anything incorrect with finding out C++ as a primary programming language. C++ is an overly robust programming language, so this is a first-rate alternative. There is not any such factor as a "no-opt for novices". The persons who say so both lacked the intellectual talents to gain knowledge of C++ or are the ones variety of persons who best recommendation what they understand and what they think is quality. Any programming language which has stuck your eye is first-rate for a newbie. If you've began finding out C++ it might be a waste to change to another programming language, as the whole thing you've discovered hence a ways is wasted. Simply stick to C++.
markhorb
2008-09-22 14:46:36 UTC
One of the things beginning programming students need to learn is not to panic because they don't understand something. You need to learn to look things up in your book and apply them.



First, you have to understand the problem. Your first function just counts vowels. No problem. How many vowels are in "hellothere"? How did you figure that out? Well, now you just have to write the steps down, one by one, on the process of counting the vowels. Next you look up the code for each step for your function.



I'll get you started on step by step:

1) get first letter

2) is letter a vowel? if yes, then add to count

3) get next letter or if end of string go to 5)

4) go to 2)

5) return count


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...