String table and printing english equivalent

This is a discussion on String table and printing english equivalent within the C Programming forums, part of the General Programming Boards category; I have a question that is still boggling my mind. Since my lecturer never gives me the answer. So, I ...

String table and printing english equivalent

I have a question that is still boggling my mind. Since my lecturer never gives me the answer. So, I decided to ask the board about this. Sorry if the post is a bit messy. Im quite new. The question goes like this.

"Write a C program that creates a string table containing the English words for the digits 0 through 9. Using this table, allow the user to enter a digit and then have your program display the word equivalent. The program has to allow the user to enter again the digit if he enters something other than digits 0 through 9."

I have created a code. I don't know if I answered the question. Can anyone rectify me if I didn't?

No you didn't answer the question and I don't even think that code will compile. Start reading through the C tutorials on this site. Once completed, sit down and think about your problem. Then write up how you would do it. Then code it and test it. Then if you have a problem come back and post.

EDIT: This code is so broken it isn't even worth pointing out the errors. You essentially came here and asked us to do your homework for you.

No you didn't answer the question and I don't even think that code will compile.

On the contrary, I think the program does answer the question, just that contains too much that is unnecessary. A quick check shows that the program will compile once the void main is fixed to int main, so I posit that it will probably compile on a compiler that accepts void main. I understand the gist of the idea behind this implementation, so saying that jimmyskabez did not do his/her homework is unfair and shows that you did not do your homework in looking at the program presented.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

I have a question that is still boggling my mind. Since my lecturer never gives me the answer. So, I decided to ask the board about this. Sorry if the post is a bit messy. Im quite new. The question goes like this.

"Write a C program that creates a string table containing the English words for the digits 0 through 9. Using this table, allow the user to enter a digit and then have your program display the word equivalent. The program has to allow the user to enter again the digit if he enters something other than digits 0 through 9."

I have created a code. I don't know if I answered the question. Can anyone rectify me if I didn't?

In deference to my esteemed colleques... your code may give you the right display, but it's not very good at the job...

1) The correct form of main() in this case is int main (void) and it returns an integer error value to the OS on exit (usually 0).

2) Never, ever, call main() recursively .. and especially not from within a function!

3) Moving 90% of your code out of main() does not a good function make. Functions should do one task. In your case, the best function would take the integer value of your user's input (which should be in main()) and print out the word corresponding to the number.

4) Passing values into a function is NOT how you create variables for use inside a function. Parameters to functions should carry needed data into a function and you should never create more parameters than you need... in your case, following #3, one parameter would suffice...

5) There is no need --or reason-- to assign 10 strings when you could just as easily use printf() to print the actual word in your switch/case statement.

Aside from this, there is a far more efficient way of doing this... Have you covered arrays in your course yet? An experienced programmer could probably do this in 20 lines or less...

Thanks so much guys for the replies. I'm still going through the tutorials to re-edit my codes. Still a new programmer. And yes, my compiler accepts void main(), that's why I use it. Some of my lecturers even use it. But, now I know its wrong so I'll change it. Thanks! Still editing. If I come up with another solution. Which may take time, I'll post it back here later.

Write a C program that creates a string table containing the English words for
the digits 0 through 9. Using this table, allow the user to enter a digit and then have
your program display the word equivalent.

Manasij Mukherjee | gcc-4.9.2 @Arch Linux Slow and Steady wins the race... if and only if :1.None of the other participants are fast and steady.
2.The fast and unsteady suddenly falls asleep while running !

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.