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

I don't see any down-reps for you in the past month. All + rep back to June 10, where you must have been doing something people didn't like.

On the other hand you have been giving bad rep to a bunch of members in a Geek's Lounge thread.

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

Get string length.
Start at the end of the string.
If character is a SPACE, back up 1 character and repeat
When the character is not a SPACE change the next char (the last SPACE seen) to \0

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

You are so close, you have it solved, but your problem is that you need one last line of code for your GCD function:

GCD = X
End Function

Thanks for helping. I'm sure the OP has been waiting for the past 6 years for you add that piece of info so he can finish his project. :icon_rolleyes:

debasisdas commented: :) +13
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

what is the matter with this code?

For one, it's a bad title for a thread.
For two, no CODE Tags.
For three, bad formatting.
Four, old code practices from the 1980's.

First things first.
1) Read the Member Rules. Make an effective title for your thread.
2) Code Tags are described all over the site. Find them. Read them.
3 & 4) See this, this, this, and this.

The first error is a "declaration syntax error"

Given 53 lines, does this error as it is make sense?

The second says"declaration is not allowed here".

Where's here? If you were given this information -- and only this information -- what could you do with it?

Salem commented: 4 excellent points +17
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Sodabread commented: I like your answer better. +7
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Here are a lot of links about functions. If there's something you don't understand, ask a specific question. Be sure you give enough information that we know what you are having trouble with. Why does the info not make sense is something good to add.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
int main()
{	
	char call1, call2, call3, call4, call5, call6; 
	cout<<"Enter a character.\n";
	cin>>call1>>call2>>call3>>call4>>call5>>call6;
	callFunction(call1, call2, call3, call4,call5,call6);
	
	return 0;
}

Your main() makes no sense.
You output a prompt asking for a character.
Then you input 6 characters. Why? What if I enter "smiley"?

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

No thank you. I'm done with school. Now if you need help, ask a valid question.

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

I probably misinterpreted what you typed, but I think I have until step 3 I just wasn't specific:

void  deleteAllStructs(void){
 
    struct CarInfo *erasingPtr;
 
    do {
        erasingPtr=gHead->next;
        gHead=NULL;
    } while (NULL!=gTail);
 
}

Point to the line that accomplished step 1:
1) Start at head to get address of first node -- nodeA

Point to the line that accomplished step 2:
2) Get address of next node -- NodeB.

Point to the line that accomplished step 3:
3) Delete nodeA

Point to the line that accomplished step 4:
4) Move nodeB into nodeA

Point to the line that accomplished step 5:
5) Loop back to 2

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

I've been told to return 0 at the end in pretty much every tutorial I've seen but I don't because I have no idea what the point of it is and it works fine without it.

Then go into history or literature and forget programming. If every tutorial says do it, what makes you think you don't have to?

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

Nope. You only have step 5.

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

Then why are you asking? That must not be your real problem.

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

1) Start at head to get address of first node -- nodeA

2) Get address of next node -- NodeB.
3) Delete nodeA
4) Move nodeB into nodeA
5) Loop back to 2

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

so the sanity of the list wont be maintained ? in this case

No. The list will become insane (MWAHAHAAAAA) because the new 'last node' will point to the non-existent node you just deleted. You are not given the ability to fix this based on your requirements.

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

Start by learning C++. Get the basics down and then this will be easy.

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

I wrote two programs, but I'm in dire need of the third and be honest with you I could not at all to write the third program

1) Learn to format your code so it can be read and followed easily
2) See this
3) We won't write it for you. Most of us don't need the grade.

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

People thinking before posting questions in software forums. Using CODE Tags.
What a dream!

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

Wow Thanks! can you give me the link on functions pls :)

Why? Can't you look in your book? Don't you know how to use Google? Can't you think for yourself?

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

SO what do you want included in the loop? Point to the line that needs to be inside to loop that isn't already.
Finish your do-while loop.

In fact, start over. Get the program running in small pieces, stop trying to write the whole thing and clean up the problems later.
1) Start by writing the loop. Input the Y/N and continue or not based on the input.
2) Next, add the menu. Make sure it still loops properly.
3) Add the switch statement. Test it again....

Programming this way is faster and you understand each piece much better.

aiwasen commented: Thanks,i'll try +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

A very convoluted confusing question.

Ok, now I'm feeling dumb and all, but I need help on how to a print a secret random code if I said yes on cheat, and I should not let it be printed if the answer on the cheat is no(but it should still be stored in a value for later use).

You did an input and accepted a value. if you need it later, keep it.

so I'm just curious should I make the function on cheat "int cheat" instead of "void cheat"?

Do you want to return the value your got from the user? If so, yes.

cause I don't know how to give the value of cheat to main so that it can answer the question to print the secret random code.

Return it. Reread the chapter on functions.

And I need help finding out in what variable the secret code is stored in so I can print it on int main() P.S. I need it as functions.

It's your program -- put it in whatever variable you want.

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

cout is the easiest debugging tool you have.

You suspect the file is not being read? After the open, display the status of the open -- did it work? After each read, display the data read -- is it correct?

You suspect u and uc don't work? Display values before and after IF's to see if they worked properly. Display messages to follow the flow of the program.

In other words, follow the program by outputting key data and positional statements.

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

Of course. Delete the node you are pointing to.

The question doesn't say you need to clean up the next-pointer in the previous node, which you can't do, but too bad. Stupid requirements cause problems.

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

Look at your first post. Answer my questions. Post the answer.

Your second post adds nothing to the question -- the answer is already in the first post.

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

> If it is only a handful of times, what does it hurt having it and not using it?
Because any extra feature/button adds an element of confusion (& frustration) for everyone who doesn't know what it is or how to use it.

I'm sorry, but that's BS! A button that is clearly labeled multi-quote as it is on numerous other forums is not confusing & frustrating.

You want confusing & frustrating? Check out the images. I would find the rep area completely confusing and would ignore it. The cloud confuses me today, so I ignore it. Why would a well-labeled button be worse than these two things that already exist?

And if someone can't figure out what the label means, they will ignore it -- just like they already do with
1) Member Rules
2) Code Tags
3) Mark this Thread as Solved

And I offhand know 4 people that want it. Me, crunchie, Nick Evan, articlewriter1 for sure.

Maybe you can just add it as a colored square (like the rep arrows). That way it can't confuse anyone because it will just look like decoration on a post. Or Ctrl-click the "Post Reply" button. That way you won't be adding "any extra feature/button" and cannot possibly confuse and frustrate anyone because they don't know it's there.

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

Where does your loop actually start?
Where do you want the loop to start?

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

In the past week I wanted to use it 3-4 times. On PFO this week I've used it once.

If it is only a handful of times, what does it hurt having it and not using it?

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

OK, then. Get ready:
Set the textbox to a nonproportional font.
Figure out how many characters can fit across in the box
Count the characters in both fields
Subtract that value from the number of characters the box can hold
Add that many spaces between the fields

Copy the textbox.text field into the email.

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

Neither English nor French are my native tongue, is this what you mean:
http://en.wikipedia.org/wiki/Faux_pas

Yes


That's what I figured. I'm going to break lots of things testing this where I can :)

Watch out, guys! I've created a Monster! :)

By the way, regarding your .sig, I had once heard a similar definition of Congress. It goes something along the lines of Pro being the opposite of Con, therefore what would one call the opposite of Progress?

I believe I had that as a sig years ago. It's another one of my favorites. The way I've used it is
"If pro is the opposite con, then what's the opposite of progress?"

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

there is only one text box , aligning left or right will make align both coloumn in either way.

A textbox does not have columns.

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

When dealing with pointers, the "&" sign is called the address-of urinary operator. Knowing it's name sure helps to understand when to use it. Is "*" a urinary operator as well, and if so, what is its name? If it is not an operator, then what is it?

Thanks.

Urinary? I know these questions piss off some people, but really! :icon_twisted:

To answer your question, see this. Google is your friend.

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

It is really difficult to make comments on multiple posts which happens often enough to be a pain in the ass since you removed the multi-quote button.

PLEASE give it back!

jonsca commented: Only because you said please. +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Indeed, I suspected that the NULL would be added anyway, but after the end of the character array. That might mean in the memory of something else.

Exactly

Nice test. I moved the 12345678901234567890 over one character so that I could count characters (I assume this is the reason it was there anyway):

Yes. That was my faux pas... (or in English- fough paugh)

That first 7 is what is left after the end of str1b, and 4567 is what is left after the end of str1c. It looks like the memory had overflown to the next character array, but in the opposite direction that I had expected. As if str1a, str1b, and str1c are laid out in memory in reverse order, with the end of str1c coming right before the beginning of str1b, and the end of str1b coming right before the beginning of str1a.

Excellent synopsis.

Would I see that result on other compilers as well? These results are on the Kubuntu box compiled with gcc. I'm fixing the Windows VM, so I cannot test in there at the moment.

Should be similar. Maybe a compiler does not reverse the order of the variables in memory, so the result will be different, but still wrong. Maybe the program crashes because you overwrite some memory that's protected. Lot's of different things can happen, none of them good.

Did I mention how much I appreciate you taking the time to teach me this stuff? I really …

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

If its C++ then you should post in the C++ forum.

Sorry, my fault.

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

WaltP is there any example of code that you know that shows fflush in action. I believe if you use it with files it doesn't flush the buffer instead it prints the buffers information onto the file

"flush the buffer" means "it prints the buffers information onto the file".

What is your real question? You don't need an example code, you already know it's syntax. What is does is invisible anyway.

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

...........................
am asking ...if how to run this properly....when errors become 0 and =warning is 8 it wont run.........

Fix the warnings.
Use CODE Tags
And use proper formatting

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

You're going to have to contact the author of the code and get a copy of inputs.h from him. And that's not a prototype. It's an include file.

If the code really came out of the book, the include file is there, too.

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

Is there any other problem with your code now?

That code posted was not by the OP. That was simply another EGO post violating our don't do other's homework for them policy.

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

Then in that case,
1) read one value from both files.
2) compare them
3) write the smallest to file3
4) read from the file that had the smallest value
5) loop back to 2 (do NOT use goto)

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

How can I start doing a program using pop-up menus in C++? with the choices which are clickable? which code I should use?thank you.

Learn to use the EDIT button. Don't post twice.

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

First thing is to format your code properly. That will prevent the errors you have now, never to return again. Well, almost never...

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

Good to know. It works with MinGW in Code::Blocks.

Maybe so. But 3 years from now when you move to a new compiler and the code you've been using for the past 7 years suddenly doesn't work anymore, are you going to remember it might be because if fflush()? What's the chance your reaction will be "but it's always worked before!"

Stop using it now and get a jump on good habits.

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

Here is a rough example of why you would want to use it.

If you comment out fflush(stdin); then it skips asking for input every second one, but with it you get asked every time.

Completely wrong! fflush() is defined only for output streams. stdin is not an output stream, therefore fflush() is not defined and therefore not guaranteed to work. And since it's undefined for input streams, it potentially could crash the program in some compilers. fflush() is used to make sure all the output is sent to the output device. Since C uses buffered I/O, the output goes into an internal system buffer and when this buffer is full, the data is finally sent to the physical device. fflush() is used to force the buffer to be output data whether full or not.

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

my confusion is as syntax of thread creation is
pthread_create(
pthread_t *thread,
const pthread_attr_t *attr,
void *(*func)(void *),
void *arg);
how i use two arguments
int argc,char * argv[]) in it

CODE TAGS!!!! Use them!

Which parameter in the pthread_create() call is the *argv[] parameter? Same with argc. Start there.

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

Nathan is partially correct. Based on your code and assumed knowledge
1) read file 1 into an array.
2) read file 2 into an array.
3) merge the 2 arrays into a third.
4) write the 3rd array into file 3
5) Do not use sort in C++ because I'm sure your instructor wants you to learn the technique, not the C++ command.

Step 3 is the complicated one.
1) Start the indicies for array1 and array2 at 0
2) Compare the elements in array 1 and 2 based in the indecies.
3) Move the smaller (say array1) into array3. Move to the next element in array1.
4) Repeat 2&3 until all elements have been moved.

You'll have to figure out what to do when you get to the end of one of the arrays.

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

Were 3 identical answers really necessary? :icon_rolleyes:

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

That is a partial answer. The function strncat does in fact add a null character to the end if str1 was not overflown. If str1 was in fact overflown, then the null character is not added.

Again, you are wrong. The NULL is added, just not where you want it to be.

As I implied, write a test program:

#include <stdio.h> 
#include <string.h> 
int main() 
{ 
    int so, sl, n;
    char  str1a[20] = "abcdefghij";
    char  str1b[20] = "abcdefghijklmn";
    char  str1c[20] = "abcdefghijklmnopq";
    char  str22[20] = "1234567890";

    strncat(str1a, str22, 7);    printf("<%s>\n", str1a);
    strncat(str1b, str22, 7);    printf("<%s>\n", str1b);
    strncat(str1c, str22, 7);    printf("<%s>\n", str1c);

    printf("12345678901234567890\n\n");

    printf("<%s>\n", str1a);
    printf("<%s>\n", str1b);
    printf("<%s>\n", str1c);

    return 0;
}

Now why did the last 3 printf 's display what they did? Think about it... :icon_wink:

dotancohen commented: Thanks! +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What is n? Is it strlen(str2)?

strncpy(str1,str2,n) -- definition

The issue is that I cannot be certain that the length of str1 is enough to hold both str1 and str2. Such as:

char str1[16]="Have a very ";
char str2[16]="nice day!";

What would sizeof(str1) give you?
What would strlen(str1) give you?
What's left?

From this page:
http://www.cprogramming.com/tutorial/secure.html
"You should be aware that strncpy will not automatically append a null terminator"

From http://www.cplusplus.com/reference/clibrary/cstring/strncat/:
Appends the first num characters of source to destination, plus a terminating null-character.

http://en.wikipedia.org/wiki/Strcat#strncat
The most common bounded variant, strncat, only appends a specified number of bytes, plus a NULL byte.

http://www.elook.org/programming/c/strncat.html
The function strncat() concatenates at most count characters of str2 onto str1, adding a null termination.

So your source seems to be wrong. What was the result of your test to see which is correct?

dotancohen commented: thanks +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I am looking to learn best practices for working with strings. Two issues that I have with strncat are that it is difficult to calculate how much space to allow,

Why? strlen(str1) + n + 1 is exactly how much space is needed.

and that there may not be a null character in the string after the procedure.

Better read up on strncat() again. You are wrong.

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

Jeez - Ron Paul is right up there with Palin, bachman and santorum for crazy:

  • he also thinks the "War on Christmas" is real -- it is.
    and that the separation of church and state is a myth -- explanation needed. Separation doesn't/shouldn't/never did exist? What's this mean?
    He believes the founding fathers wanted to discriminate on behalf of certain religions -- they were Christians (except for a few Atheists) so by definition they did discriminate. But they wanted to at least let others worship their own way regardless.
    and that morality cannot be accomplished absent Christianity -- crap.
  • he proposed getting rid of the Internal Revenue Service -- sounds good to me. Put them all on the borders protecting us from illegals rather than accosting citizens. We'd have 5 times more border patrol than we currently have. What's more important -- protecting the population or prosecuting the citizenry because they can't make head nor tail of taxes? 92,000 IRS employees, 20,000 border agents. Who's more dangerous according to the government? (sorry GJ)
    income tax -- won't happen but it needs a MAJOR simplicity overhaul.
    the Federal Reserve -- how's this supposed to work?
    withdrawing from the United Nations -- nah, they do some good work.
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1) until you completely understand how paths work in relation to your IDE vs Program, use the full path.
2) You don't check to see if the file was opened. It probably was, just not where you expected. Always error check after anything that might not work.