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

the value stays the same 1010 1011 if i use char or unsigned char. even if i use 171 or -85 does not matter, how is it ?

The 8 bits used to represent -85 and 171 in binary are identical. For a signed value, the first '1' is the sign bit.

the only value that is displayed is changed if i cast to char or unsigned char.

No idea what you mean.

Yes this is about assigning values. You can look at them as byte that represent char or unsigned char no ?

Yes.

There is bit that represent sign so char is not 8bit it is 9 ??

No. A char is always 8 bits*. An unsigned char uses all 8 bits. A signed char uses 7 bits + 1 sign bit.

----------

(* please don't be pedantic. do not confuse the matter by pointing out different systems/environments vs char sizes. the environment here is obvious.)

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

That's what tutorials, books, and teachers are for. We are not a teaching site.

Yes, I know it's simple, but you try to do it, and we can help you fix it.

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

So what was the problem? And your solution?

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

In fact, Niklaus Wirth programmed the second and subsequent versions of his Pascal in the previous version of Pascal.

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

Even before the pervious question is answered question 2 is nonsensical. C++ could be written in ForTran or Cobol if the creators desired.

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

Problem is your are using system(pause) to pause your run. You are waiting at the OS at that point, not your program.

C++ has input functions, like cin, getline(), etc that waits better than system(pause). Use them instead. There is no reason to call the OS to pause any program. Same with cls...

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

Look at string functions left$(), right$(), len()

Use s FOR loop over the string read in.

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

Hi everyone,I'm tryind to do something about sound on linux.I basically record some sound and try to encyrpt it using algorithm.However,I encountered some sort of pointer problem.Both RSA algorithm and recording&listenin sound works properly.
- - -
Basically,Rsa works with ascii array which includes char's of my word and encyrpt/decyrpt asciis with rsa.Here is my RSA algorithm which works properly separate with sound.
- - -
Here is writing&listening from sound card.It'S also works properly.
- - -
I'm new with C language,so I've little idea how to deal with arrays&sizes etc.Therefore I didnt combined both RSA and sound algortihms in 1 one code.Any help would be appriciated.

OK, you say all your parts work properly.
You don't know how to deal with arrays and sizes (so how can it work properly?)
You encounter "some sort of pointer problem"
Then you post almost 600 lines of code with no explanation.
How are we supposed to locate "some sort of pointer problem" with no clue where to look nor what to look for?

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

Multiply i by 3. Try it. You'll like it.

Talk about blowing your array limits!!! 8o|

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

Well, based on the code you posted, there is nothing wrong. So, either
1) you're are not understanding what you are seeing
2) the problem is not in the loop
3) you have a definition somewhere that's wrong and you're trouncing memory you shouldn't be touching.

Try adding printf() statements to check values at key places in the program.

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

I have a for loop like this:

   for (i = 0; i < max; i++)
    {
     ...
    }

But when I run it, i is being set to max

If I set i to 0 in the first line of the for loop, it does change to 0, but at the end of the for loop, it does not go back up and check the condition, it just exits out of the loop.

Then max is less than 2.

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

While \v is something I've never used, I have used \f. On output it will generally form feed, kicking out the page when encountered. It's the code that is used when you do a page break in your word processor.

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

And am sorry but "THIS IS NOT CHEATING".

It is if we say it is...
As a moderator of these boards with over 10000 posts I know the definition better than you, with your total of 3 posts.

I CANNOT accept this word to be said for ME.

Then don't post working code as an answer to a question and you will not be a cheater. Give guidance instead. This is all I'm saying. Don't post working answers.

Am a software engineer with experience more than 3 years in one of the most important companies of the middle east

So? I'm a software engineer with over 30 years experience with top companies in the US. What of it? I've also trained and taught courses. I also play Backgammon and Go. So there... ;o)

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

i have the whole right code for this program

do you need it ???

is not an offer of help. It's an offer to cheat.

We have no problem with your membership. We simply give guidance, not working code, when we answer questions. This way the student learns and corrects the program himself.

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

i have the whole right code for this program

We don't do homework for people here. This is not a cheat site.

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

cout is not C, it's C++. And it also is less versatile than printf()

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

Grossly unreadable.

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

Print your code.
Sit at a desk with a pencil and the code.
Write down the names of each variable in a column.
Go through the code line by line changing the variable values as you go.
Follow the loop until it exits.

This is the easiest way to figure out what's wrong with your code. You also learn more about programming.

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

Why do people always need to seek to get the length of a file? In this case, you want to read the header, right? How big is the header? Just create an unsigned char or byte array to read in a chunk of the file -- 512, 1024, 2048 bytes...

The line char newchar = buffer[4]+buffer[5]+buffer[6]+buffer[7]; simply adds the bytes together. What are you trying to do here?

it is displayed as a question mark in the command prompt.

Of what use is displaying a binary file at the command prompt. As rubberman suggests start by displaying the data as a series of HEX bytes. But use be sure to use them as unsigned values because bytes are neither positive nor negative.

trishtren commented: your suggestion is helpful, and the adding the bits together was to try and collect only the bits after FWS, as that already worked i only wanted the version number located from bit 4-8 to be converted to unsigned int, but im still a rookie at following t +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Another disagreement was with braces - where to put them? Since I scan the code more like it is for script languages (like Python), that is ignoring braces and looking only at indentation, I went for the more compact style of putting the opening brace on the same line as the control statement.
Closing one goes - as I see almost everywhere, on it's own line.
How do you indent?

My style is:

    if (comparison)/For()/etc...
    {
        block
        command
        section
    }

Braces on their own line. Everything between indented 4 spaces.
If I end up with 5 or more nested blocks (a very rare occurence) I'll switch to 3 spaces.
I personally find 2 spaces too few.
Indenting one space - why bother?
Anything more than 4 is too far. And NEVER use TABs!!!

Naming stuff -- no hard-and fast convention. Generally:
All CAPS for constants.
WordCase generally for functions
wordCase for variables

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

Don't do everything from scratch though. Do yourself a favour and take a look at Boost.Spirit.

I disagree.
1) Boost is unnecessary
2) It's better at the early stages of learning to do things by scratch*.
3) It's also non-standard...

When you change languages/systems, Boost may not be an option and if that's what you learned you are SOL and can't write the code.

Things like Boost are not for learning. They are used to make your life easier after you know what you are doing.

* and it's obvious Dasttann777 is still learning.

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

didn't i just say that he needs to do it, where did i say it is not possible ? ?

Sorry, Sokurenko, if that's what you meant. The way it reads is by calculating all the values and he only needs 'A' and 'a' added my suggestion is cumbersome and prone to not working.

But then again, isn't it obvious? I'm somewhat old school and rather than tell people book:chapter:verse:word, I give them basic information and allow them to think about how to implement it. I wanted reyesg to figure the addition out himself...

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

I am getting a crazy number of errors that i honestly do not know what is wrong. I am getting a syntax errot before the "int"s in the switch, and conflicting types of all the function names. Any help will be appreciated.

Then reread the section in your book on how to call a function.

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

Yeah, it's quite impossible after collecting all the letter counts to figure out how to combine the counts for 'a' and 'A'...
(i wish we still had the roll-eyes -- i like to mark sarcasm in case Sheldon Cooper is reading this...)

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

Each character has a numeric value. 'A'=65, 'B'=66, 'a'=97, etc. There are 256 possible values.

So read a character. Use the character as an index into stAlphabet[256] and increment that value. When you hit the EOF, you will have the count of all characters in the file.

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

Then you are using the wrong 'read' command. Don't read a word at a time, read a line. Try getline()

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

Why are you doing all that crap with tokens, fseeks, and stuff?

What's wrong with:

open file
while not EOF
   read addressA
   read addressB
   read package
   read number
   process data read
end-of-while
finish the program
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Finally, a lot of the younger members are probably unfamiliar with flowcharts; they are generally considered obsolete,

Really? When did this happen? What superseded it -- at least from a student standpoint?

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

But I really want to learn about it in c++, because I would like to improve myself in that language :)

Why is it people always want to "improve myself" doing things that the language makes it difficult to do and can only be done in rare cases in the first place. What you want to do will only work on the operating system you learn it on -- so it's use is limited and questionable.

To "improve myself", try doing things the language is meant to do, and is easily portable from system to system, compiler to compiler. If you are coding in a non-standard non-portable way, learn the standard portable way to program to "improve myself".

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

i think you could use a
std::map<std::string,std::string> _q;

Look at his code. Is he anywhere near understanding std::map when he can barely understand IFs?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
include<conio.h>

Don't include that non-standard hassle-prone header. The sooner you get away from using it, the sooner you can call yourself a real programmer. there are explanations why all over these forums.

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

Kool!!!

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

Yes, you're going in the right direction...

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

My problem is when I compile each file separately I get the error: 'Undefined reference to ReadFromfFile()" (Note: ReadFromFile is a function defined in definition.c and I get this error when I compile the main.c file)

Your compile is also linking, and definition.c was not specified.

And when I compile the definition.c file I get the error 'Undefined reference to main'.

Same.

In both cases, if you compile only it should work. But why bother. Linking is the magic.

And when I compile all my files together as such: gcc DeliveryServices.h DeliveryServices.c main.c -o Servrices: I get the error 'Segmentation fault(core dumped)'.

You don't specify the .h files when compiling. The compiler will find it because of the #include statement.

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

I do...

If you want help, you have to provide the work, we can provide direction and suggestions.