WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why is ht_put() receiving val as a void?

printf("\n\n\tEnter name: "); // <- this does not work, all names get same phone number

Add fflush(stdout); after the printf() to display it if it isn't working. Your input is being buffered...

Also, see this series about scanf() and what to use instead.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why can't I post a response without making it code? There is no code at all in a response I made and I cannot get it posted because I recieve the error:

If posting a code snippet, use the Code button in the editor toolbar

The code snippet in your post is formatted incorrectly. Please use the Code button in the editor toolbar when posting whitespace-sensitive text.
Post: Markdown Syntax: Formatting Help

http://www.daniweb.com/software-development/cpp/threads/422081/phone-management-system#post1801434 is my post...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hi!

Hi.

I am working into the development of a C++ related Phone Management System where the request is to:

  1. Input information of new subscriber: The program should input a line of data from the keyboard in the following format: <surname> <name> ! <telephone1> <mode> ! <telephone2> <mode> ! ...! <telephoneM> <mode>. The mode field gets values from the set (Y, N), where it describes whether a user’s telephone number is available to all other subscribers or not. The input data line should end with the character Ctrl-D (end-of-file/EOF). The program should store the data as strings (or char strings), without further processing, in an array of strings (or char strings). Assume that the maximum size of an input data line is 80 characters.

OK. Sounds like it's possible

I need some help in order to begin as there is a number of functions to develop and my big query is how to handle registration first...

Makes sense. Most people need some help with something. But your query shows you have no idea what you need to do and we are not a programming service and won't design and implement your project for you. Looks like you need to think long and hard about what you need to do to start your design.

Your description is your design, you just need to lay out the steps needed to accomplish it.

Thanks

Welcome.

.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Also, what's the magic number 12 for? And what does x=x/10 do? Why is it in your FOR statement?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

First you understand how a for loop works.
Then understand all the pieces of the for loop expression.
Next, look at the posted code and figure out which of those pieces are there.
Put those pieces into the for loop syntax

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You initialize a variable to give it a starting value if you need to use it.
To initialize the variable you assign a value to it.

So initializing means making sure you know the variable has a valid starting value.
Assigning means putting a value into the variable.
Slight definition difference of the same thing.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1) Look up how and why to use srand(). You are using it wrong.
2) Using the technique you tried will work -- if you add one more step.
After using colors[pos]; you need to remove it from the list by moving all values after it down.

In other words, it your array starts as ABCDEF and randomly choose C, you need to modify the array into ABDEF before choosing the next value.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

post your code so we can attempt to clean and or fix one.

No, post your code so we can help you fix it. We don't clean and fix here -- the OP learns nothing if it's done for him.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

what you've shown me is correct!! but is there any way to know that 25-2i or 40-3i will give me what i want???

Yes. Sit down at your desk with pencil and paper and plug values into the variables. See what values are generated and draw out what they indicate.

Pretty much what you'd do in any math class. Works in programming, too.

zeroliken commented: true story +9
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

YAJUTBIFSYDHTLHTRP suggestion...

(yet another just use the built in function so you don't have to learn how to really program)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

well, i made it using void main() and it executes fine!!
then what is the problem???

So you'll read his link but not mine, eh? Fine... :-p

Just because you can drive without stopping at red lights, does that make it OK?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

and you can use void main() there is no need of making it int.

Absolutely incorrect. See void main()

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You need to think through your problem more carefully, Given any input:
1) How many numbers do you have to test to find x primes? What kind of loop is best for this?
2) How can you count the primes you find so you know when x have been calculated?

And for your input, use while since you know how it works. Right now the user can break your input easily.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Your question makes no sense. Please explain in more detail with and example or two.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Okay, I know there is a prior article about this, but I used { } with my if statements, and it's still not working... is it because I have multiple if statements consecutively after another?

No, it's because you have formatting that hides your problem. See this for proper formatting suggestions.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look up
va_start,
va_list,
va_arg,
va_end

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why does everyone think new is the way to create static arrays? What a waste of resources!

Use a 2D array, row=number dialed, col=letters:

char letters[10][4] = { {'-','-','-','-'},  //0
                        {'-','-','-','-'},  //1
                        {'A','B','C','-'},  //2
                        {'D','E','F','-'},  //3
                        {'G','H','I','-'},  //4
                        {'J','K','L','-'},  //5
                        {'M','N','O','-'},  //6
                        {'P','R','S','-'},  //7
                        {'T','U','V','-'},  //8
                        {'W','X','Y','Z'}}; //9
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Start calcumating prime numbers. When you've calculated x of them, there you are...

And your tests for bad values of x would be better if you used a do-while loop.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I held these until the shakedown was fairly complete. Here are a few of the useful but dropped functions that IMO need to be reimplmented. But #1 is in fact a bug:

1) Any threads I post in are never marked NEW. For the threads I haven't posted in it's a crap shoot whether they are marked NEW or not. Most threads, no matter how many times I mark the forum read, show up as NEW. This might be tied to whether I actually looked at the thread. If I mark the forum read, all threads should be marked as read permanently until a new post is made.

2) The NEW/Target Icon needs to jump to first unread post. The technique with the current setup is
a- click on the message title
b- click on the LAST page if necessary
c- try to remember what message was last seen and/or how long ago the thead was looked at (with vague HOUR and DAY indicators)
d- if necessary, click back a page and scroll all the way to the bottom to find that last post.
This is a HUGE PITA! 2-3 clicks, sh!t loads of scrolling, and memory excercises. Not user friendly.

3) Please add the post number back into the post header. It's really helpful to see what post # is being looked at.

4) I QUOTE a lot so there is no confusion as to what I am referring to in my responses. Highlight- …

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Then why do you use %d for your input if you want to enter strings? Look up and study the printf() formatting characters again.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

For you menu i would add a system("cls"); that will wipe out the screen

NO NO NO NO!!!!!! It's bad form and non portable to call system commands...

2 - use getch() maybe,

I repeat, NO NO NO NO!!!!!! getch() is only available in a couple compilers, therefore non portable and non standard...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1.How to get the name including the spaces?

Use fgets()

2.How to press make program to skip question when pressed "n" and when invalid answer like 17u to show error?

The question is unintelligible.

3.How to generate random perfect square no. and how to generate random numbers for (num1,num2,num3) [I always get the same no. when running the program]

When looking up rand(), you undoubtedly came across srand()

4.How to make a timer for the quiz (am currently limiting it to 10 question but assignment need it to end after 60 sec)

use time()

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Correct on the first 2.
Wrong on last one. There's no compare and no XOR...

But what do they mean

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What do you think they do? If you try to explain them, we'll tell you where you got it wrong.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Not so sure about DWBB. Looks too much like dweeb.

zeroliken commented: lol +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

[boilerplate_help_info]
Posting requests for help must be well thought out if you want help quickly and correctly. Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful? Check your post with these checkpoints - what is it you missed:

  1. Ask a question that can be answered. Do not ask
    -What's wrong with my code?
    -Why doesn't this work?
    -Anything else that does not give us useful information.
  2. Post your code. If we don't know what you did, how can we possibly help?
    -Use PROPER FORMATTING -- see this
    -Use CODE Tags so your formatting is preserved.
    If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable.
  3. Explain what the code is supposed to do. If we don't know where the target is, how can we help you hit it?
  4. Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
  5. If you have errors, post them! We can't see your screen. We can't read your mind. You need to tell us what happened.
  6. Do not ask for code. We are not a coding service. We will help you fix your code.
    -If anyone posts working code for you, …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Doesn't anyone ever bother looking at their message before posting?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes we can help. See points 1, 2, 7, 9, 12. But don't ignore the rest...

[boilerplate_help_info]
Posting requests for help must be well thought out if you want help quickly and correctly. Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful? Check your post with these checkpoints - what is it you missed:

  1. Ask a question that can be answered. Do not ask
    -What's wrong with my code?
    -Why doesn't this work?
    Anything else that does not give us useful information.
  2. Post your code. If we don't know what you did, how can we possibly help?
    -Use PROPER FORMATTING -- see this
    -Use CODE Tags so your formatting is preserved.
    If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable.
  3. Explain what the code is supposed to do. If we don't know where the target is, how can we help you hit it?
  4. Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
  5. If you have errors, post them! We can't see your screen. We can't read your mind. You need to tell us what happened.
  6. Do not ask for code. We are not a coding …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Doesn't that link in the upper right corner of the input box labeled "Formatting Help" tell you anything? I'm told it explains how to post code...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'm not getting correct results.

In your FOR statement, if you get an alpha, you copy all the characters in sentence1 to sentence.
Why not just copy the one alpha you found.
When you're done with the FOR loops, how do you know you copied the sentence correctly? What's in sentence after the FORs?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Is it a C++ 'string' or a c-style 'c-string'

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Study.
Get a graphics addon that can color text.
Learn all the C++ reserved words (if, while, switch, ...)
Decide how you want the output to look (what gets colored green, what's red, etc)
Go slowly, compiling often.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Then try adding '\n' to the end of your printf() message.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What does that mean? How can your code stop working when you compile it?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I am having trouble reading your code

Because he didn't bother using CODE Tags... Maybe he can repost the code properly?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Read your condition while(n<=5) cout error out loud and listen/think about what you're saying. Does that condition do what you want?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Tygawr (no one else!!!!), what does substr() do? Please explain. And how does it help you

parse through it [the big string].

???

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Seems to be what Moschops said 2 days ago...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Expanding on MNeal's post, stop using magic numbers. If you want to test for the character 'A', use 'A', not 65. Zero is '0', not 48.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

When pasting code, all you need to do is highlight it and either click the Code button or hit the Tab key on your keyboard. And if manually typing code into the editor, it preserves your indentation level like a real IDE would. It's actually EASIER for me to intent code than manually add [code] above and below a post because it's just hitting one key, once, versus twelve keys (for open/close code tags)

But I've always found it easier to hit the CODE indicator and paste the CODE between the [CODE][/CODE] marks, rather than pasting the code and going back to highlight the code. Same with Bold, Italic, etc. I would like to see clicking a command placing empty indicators into the message like before.

And to prevent the "Huh?", I mean when I click Italic with nothing highlighted, two stars are placed in the message field and the cursor placed between them. Same with Bold, Code, Inline, etc.

And Quotes just seem to be a pain in general. Isn't there any way to quote without copy/paste -- like before the change? If not, is it on the todo list?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

First question, what does EOF have to do with this problem?

The solution has to do with being able to read non-digit characters without causing an error. Search for the thousands of responses to this error using "scanf integer character input"

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look at each character until you find the first character in the find-string. Then check the following characters with the rest of the find-string.
If a mismatch is seen, you haven't found a substring. Continue looking, starting where the first character was found.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes, IF we knew what you needed hwlp with.
1) Use CODE tags around all the code
2) A complete explanation of what you are trying to do and what actually happened is necessary.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1) I don't see where you are displaying the size of the buffer, only the size of the file from ftell().
2) The calculated size of the file from the copy function is lost so you really have no idea how big the buffer is.
3) The buffer you allocated is never free'd causing a memory leak.
4) The fseek() calls are different. I understand they should mean the same thing, but you want to test oranges to oranges, not oranges to tangerines.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Follow the Dragon's suggestion. Ignore SRE93's

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Your problem is trying to understand the concept by reading code. You need to understand linked lists in general before you deal with the code. Then you will be able to see what part of the code equates with what part of the concept.

Search out a detailed generic explanation of linked lists, then go back to the code and see how the code replicates the explanation.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

When you read using fgets() and the line is longer than the buffer size (or bytes to read) the next read will continue where the last read left off -- in the middle of the line.