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

Think about how you want your breakpoint to work.
What happens when the breakpoint is activated?
What does the user get to do when your breakpoint is activated?
How do you want to continue from the breakpoint?

Figure out all the ins and outs of your breakpoint concept.
Once you have that designed, then you are ready to code it.

As for int 3, forget it. I doubt strongly it's what you want.

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

And what part of "*don't use gets() *" is so difficult to understand?

If you want further help, start using the help you've been given. Otherwise, why should we bother?

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

What's the error at i=n;?

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

Repeat#1: You are looking for something specific!!!

while(i < emails.length())
while(s > 0)
while(e != emails.length())

Not one of those while statements look for anything specific

Repeat #2: Each loop should be only about 2-3 statements

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

1) You are still using a FOR loop
2) You are still nesting your loops

How about:

While Loop to find the @
  End of loop

From @ position:
While loop to find beginning
  End of loop

From @ position:
While loop to find end
  End of loop

Do NOT use while(true), that is not an appropriate condition in your case. You are looking for something specific.

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

There are a number of issues with your code. The first one is merely for clarity and speed. Basically the isValidCharacter function can be 1 line:

For speed, yes. Clarity, no. IMO, your 1-liner is not as clear as the original. That's not to say the original is clear, either. It really isn't.

In my years of programming, I've found you program for clarity or speed. Rarely can you program for both.

Here's a full listing of my code with lines added for debugging.

Why? It's going to take longer for the OP to compare your code with his to get any real understanding (he's new, remember) so it would be easier just to replace his with yours. That's not what this board is about.

And a finite state machine??!?? He can't even parse an email! How is he supposed to program a finite state machine? And what would his instructor say about it? ;-)

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

First off, you should use WHILE statements instead of FOR statements. You are not iterating through the string a set number of times, only until a specific condition is met. This will also let you process the string in 3 distinct segments:
1) find @ and end this loop
2) find beginning and end this loop
3) find end and end this loop
Each loop should be only about 2-3 statements

You have the loops interleaved making it harder to follow (also your indentation is inconsitent also making it hard)

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

will this work sir????

What part of

you need to use an intermediate integer.

int a,b,temp;

temp = a
a = b
b = temp

did you not understand?

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

Games.
Mastermind, Craps, Hangman, Lingo....

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

Convert the numbers to a string then concatenate.

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

for (i = srclen, j = 0; i < srclen && j < dstlen; i++, j++)

If i starts as srclen when will i < srclen be true? What happens to your loop in this case?

IMO, you need one more index value. Since you have srclen and dstlen you should have 1 more: resultlen

First Loop: resultlen starts at 0 and is incremented for each character added.
Second Loop: resultlen continues from where it left off...
Next: if you want a result string, where's the terminating \0 at the end of result?
Third loop: why use the complex printf() to output a single character when the simple function putchar() is created just for that purpose? Or if you actually make a result string, forget the loop and print the string itself.

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

Yes, ASM can be very useful. If you need to rewrite a function because its too slow, ASM can make it quite a bit faster. If you need to interface with a module of some kind and C++ is too clumsy to do the interface, ASM to the rescue. Drivers can easily be written in ASM.

How do I know which register to put stuff in?

If you are calling a function, interrupt, or something already written, that info is in the documentation of the function. Otherwise, general registers are used as variables so it doesn't matter. Some registers have specific definitions, so only specific type of data will do into them. You learn what's what as you learn ASM.

triumphost commented: I see I see. +1 +5
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The closest is a character array:

char *name = "Jody";       // create a pointer pointing to the name of 5 chars
char name2[] = "Mary";     // create an array of 5 chars to hold the name
char name3[20]= "Janine";  // create an array of 20 chars to hold the name

Since they are character array 'strings' they all end in '\0' designating the end of string

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

@deceptikon

brother's wedding going on, that, coupled with him letting me play with his leica m8 while he's busy being the groom is turning out to a major distraction. :D its the reason for this late reply.

There is no need to apologize for late replys. We are not timing anyone. What makes it late anyway? For all we care, 2 weeks later is not even a late reply.

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

1st: Store the password in a file. Read it in for the compare.
2nd: For more security, encrypt the password somehow. Decrypt it before comparing.

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

I looked up the format but it looks nothing like a bitmap...

Why should it look like a bitmap? It's a PNG format.

... and I read the GDI doesn't support PNG's. So how does LibPNG do it then?

By not using GDI I suppose. Since it's called LibPNG, it was probably designed to deal with PNG files specifically.

I don't want to use LibPNG or anything. I want to do it myself.

Then you need to completely understand the PNG format. More study is necessary. Aren't there books that discuss the format? Since it's a free format, there are sites that discuss the format.

I tried changing BI_RGB to BI_PNG but that just corrupts it all.

Does that surprise you?

There isn't a single tutorial out there on reading and using the PNG format with C++.

You need to understand the format itself, irregardless of the language you want to use. The format is everything. You don't want to learn how to read with C++. C++ is just a tool. Once you understand the format, you can use any tool you want, including C++.

Reading images is not a simple task. They are quite complex in design. You'd be better off with a tool designed to deal with the format rather than designing your own.

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

Secondly, never, ever use gets, always use fgets, so not gets(sh); but fgets(sh, sizeof sh, stdin); it is safer since you can't overwrite the buffer,...

And the exact same thing goes for using scanf() to read strings. It's as bad as gets().

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

#define FOR(i,a,b) for(int i=a;i<b;i++)

Why? What's wrong with just using the for statement? Making it a define simply makes the program confusing.

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

How to figure out logical solutions to problems would be a good start.

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

It's a pointer that points to a pointer that points to a char

As for how it works, work it out. Draw a map of memory and see how it could possibly be layed out and used.

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

Problem #1:
Never ever put code or variable definitions in a header file. Header files are used to declare functions and variables, not define them.

Problem #2:

void showList(const int list[], const int n)
{
    cout<<"The list is ..... " <<endl;
    for (int i=0; i<n; i++)
    {
        cout<<setw(8)<<right<<list[i];
        if ((i+1)%1000==0)        // What are these 2 
        cout<<endl;               // lines supposed to do?
    }
    cout<<endl;
}

Problem #3:
In all your functions, why are there so many blank lines? It makes the code very hard to follow.

I've looked through the program through the call to printList() and don't see any problems with crashing. You might need to be more specific.

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

Apologies.

If I knew what was wrong, there wouldn't be a problem.

Obviously you don't know what the problem in the code is, but something happens to make you say it doesn't work. That's what you need to describe clearly

If your asking what happens when i compile, then the program just crashes.

It obviously doesn't crash when you compile. If it did, the compiler crashed -- I doubt that. Therefore I assume you mean it crashes when you run the compiled program. Describe how it crashes -- error messages, any output, etc.

while(sscanf(line,"%d", &data[y++][x])); /* i found this line online so i dont really understand why there is a while and why its not working */

This is your problem.
1) If you don't know why there is a WHILE there, why did you put it there?
2) If you don't know why it's there and it's not working, maybe that's the problem.
3) Why would you just use a random line you found online and expect it to do what you want?

What is that line supposed to be doing? How many times?

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

If you don't understand what you are writing, you should not be writing code. You need to sit at a desk with pencil and paper and plan -- yes plan -- what you need to accomplish.

Write down what the task is.
Break that description into pieces -- like in English class, what are the nouns, verbs, and the implied parts (but don't really look for nouns and verbs -- that's English class)

Write down how you accomplish each task. Then break that down into smaller pieces until you get to the point each step is as small as it can get.

There's your design. Now run through it by hand to see if it does what you want. Write down variables as they change. YOU be the computer and that description is your psuedocode.

When that's done, works, etc., now you're ready to start coding. Take a section at a time. Do the input. Get it working completely. Add the output. Get it working. Then one more step. Get it working. Add another... ad nauseum.

That's programming! (sorry, but that's really how we do it.)

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

My program thus far is not working out...

Why is it no one likes to explain what the code does wrong and expects us to figure it out for ourselves?

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

erm, whats wrong with my code? anyone can tell?

erm, not if you don't tell us where the errors are...

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

255 is -1 in 8 bits.
65535 is -1 in 16 bits.
Your 255 in the G section is getting promoted to an integer

Instead, try shifting then ANDing to get the correct bits, using the 32 bit cast:

inline RGB Rgb(int R, int G, int B) 
        {RGB Result =   (((uint32_t)R << 16) & 0x00FF0000) | 
                        (((uint32_t)G <<  8) & 0x0000FF00) | 
                        (((uint32_t)B) & 0x000000FF);
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

This is a joke, right? It has to be a joke, because neither is it true nor does it have anything to do with the OP's problem.

Based on his actual problem statement, it looks like buffered input is his problem. Maybe his description was still ambiguous and confusing since it wasn't a linear description of the problem -- or was it?.

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

You are missing endl or flush at the end of most of your output statements.

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

I have problems in this section of the program

Are your problems a secret? Or would you care to enlighten us? We aren't psychic...

I've noticed most of your initial posts are a comlete waste of your and our time since all you do is post code and ask for help, but you never explain what your problem is. Help with what? It would be beneficial to learn how to ask a question rather than making us play 20 Questions with you until we pull the question out of you.

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

Vernon Dozier said

Indent your code. It's impossible to read.

You've ignored him. If you are going to ignore the help you have already been given why should we help you further?

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

Do you understand what endl does? Look it up...

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

Do you have a question? A problem?

If so, you might want to explain...

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

I think END keyword will finsih the line and bring the next output in the next line so avoid the keyword.

Not quite. endl will. Alternate is to use ends to avoid the newline

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

1>c:\users\will\documents\visual studio 2010\projects\sdl test\sdl test\main.cpp(43): warning C4715: 'load_image' : not all control paths return a value

The function load_image has returns that do not return a value.

1>c:\users\will\documents\visual studio 2010\projects\sdl test\sdl test\main.cpp(43): warning C4715: 'load_image' : not all control paths return a value

The function load_image has returns that do not return a value.

1>playa.obj : error LNK2005: "void __cdecl apply_surface(int,int,struct SDL_Surface *,struct SDL_Surface *)" (?apply_surface@@YAXHHPAUSDL_Surface@@0@Z) already defined in main.obj

The function apply_surface() is defined more than once in the program.

1>playa.obj : error LNK2005: "struct SDL_Surface * __cdecl load_image(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?load_image@@YAPAUSDL_Surface@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in main.obj

The function load_image() is defined more than once in the program.

etc...

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

Use if statements.

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

That completely depends on the error. Since you didn't bother to tell us what the error is, we have no idea.

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

while(read(readfd, comm, sizeof comm) <= 0){}

What is this supposed to do?

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

We are not a homework cheat site. You have been given the steps needed to process one line. So process one line.

Also, read the member rules again. Note carefully the rule that states
Do provide evidence of having done some work yourself if posting questions from school or work assignments

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

Don't need arrays.

Set *total* to zero
Read a number
if not -999 
    Add it to *total* 
  else 
    print *total*

And format your code.

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

......????

......!!!!

Reread deceptikon's first sentence in the previous post. Answer that question.

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

You never defined tmpstr except as a pointer. There is no storage space associated. Therefore
strcpy(tmpstr,tekst); copies into never-never-land, and therefore blows up.

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

Try the documentation for the compiler.

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

is the problem because of the compiler?

No. You have C++ Strings and you have C-strings. Both are different and not interchangable.

Some functions have been designed to use C++ strings; some use C-strings. The documentation of each function tells you which one you need to use.

Some compilers will make extensions (added abilities) that the standard C++ definition does not describe. If both C-strings and C++Strings work in VC++ they made an extension so it will work for their compiler but not others.

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

Test each value entered. Make sure something was typed in. Are string.lengths greater than 0? Are numbers not 0?

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

What format is the time in the file? Binary? Text? Other?

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

1) Turn the computer off.
2) Sit at a desk with pen and paper
3) Write down the functions you need to create (add, delete, search, ...)
4) Take each one at a time and write the steps needed to accomplish them -- in great detail
5) Run through the steps a line at a time adding, deleting, etc. untill you know what you wrote works well.
6) Turn on the computer
7) Translate what you have into code.

This is the best, fastest, easiest way to program. 80% at a desk, 20% at the computer.

Think of anything that is to be created -- building, car, whatever. How much time do you imagine is used designing the thing vs. actually making it? The same with programs. More planning and design than typing code.

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

Now, the second while loop (line 4) I don't understand. What happens first? The assignment (base)=(add) and the increment of pointer positions? Or the other way around? First increment of position, and then assignment.

Think about how a while loop works. In general what's done first -- the comparison or the inside of the loop?
In other words, given while (A) B;
Is A first, or is B first?

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

How did you find the website before? How do you think you can find another website with similar information?

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