Narue 5,707 Bad Cop Team Colleague

>Well, apparently you've never heard of my school.
Apparently every school on the planet is incompetent, because your "problem" seems to be the norm. :rolleyes:

>I'm not looking for someone to do my homework for me. I just need a hint on where to start.
If I were you, I would take some of the knowledge obtained from my Java courses and apply them to C. The meat of programming is language independent, so you really can't use the "I know Java but not C or C++" excuse.

First, you need to understand the problem. Then you need to work out the steps for solving the problem, preferably on paper and completely by hand. Even a "complete beginner" such as yourself should have little trouble working out the basic steps in an unfamiliar language with a complete understanding of how the solution should work.

When you have a specific problem (ie. something besides "I don't know where to start"), I'll be in a better position to help you.

Narue 5,707 Bad Cop Team Colleague

>I'm not lying!
Sure you are. Are you trying to convince us that some school actually gave a complete beginner code and logic that would typically be reserved for second or third semester programming courses? Your post shows all the signs of a slacker who's suddenly facing a failing grade for his laziness.

We'll still help, but you're going to need to do more than just show us code that your teacher probably gave and in a lame attempt to appear as if you're doing work.

Narue 5,707 Bad Cop Team Colleague

>if (gallons == a - z || A - Z){
There are several things wrong with this. First, you're testing the value of characters, so you need to be surrounding them with single quotes. Next, you need to recompare with every part of the expression. C isn't polite enough to assume what you're doing. Third, your logic is faulty. And finally, testing gallons against a character is doomed to failure because it's a float. If it were a character, you could do this:

if ( gallons >= 'a' && gallons <= 'z' ||
  gallons >= 'A' && gallons <= 'Z' )
{

However, in reality, you have two choices to validate a float. First, you can use the return value of scanf, which is (put simply) the number of successfully read values matching the format string:

if ( scanf ( "%f", &gallons ) != 1 ) {
  // Invalid input
}

The second way is much better. Read all input as a string and validate it while in memory. Then when you're sure that it's legit, you convert to the appropriate type. That's probably too advanced of a solution at this point, so you'll probably want the scanf solution.

Narue 5,707 Bad Cop Team Colleague

>I'm completely new to C++, and my teacher gave us a card game to do for our first assignment.
One of these statements is a lie.

Salem commented: spreading rep - Salem +3
Narue 5,707 Bad Cop Team Colleague

>printf("%c", len_char); //<----this does not print anything too!!
What did you expect it to print? You realize that the %c format modifier takes the integer value you supply and prints the character representation of that integer, right? In other words, it's not going to print '3'...ever. As long as the lengths are single digits, you can say len_char + '0' and get the correct representation, but once the length exceeds 9, you're SOL with this method.

WolfPack commented: お帰りなさい。 +4
Grunt commented: So here comes back the great Narue- [Grunt] +2
~s.o.s~ commented: welcome back Miss Narue [~s.o.s~] +3
Narue 5,707 Bad Cop Team Colleague

^ keeps this thread going through his lack of creativity. ;)

Narue 5,707 Bad Cop Team Colleague

Then post your current code, the file you're using, and tell use what compiler and OS you're using.

Narue 5,707 Bad Cop Team Colleague

My brain hasn't been working to well lately, sorry about that. :p You want "r+b" because the "w" mode always empties the file if it already exists.

Narue 5,707 Bad Cop Team Colleague

The "a" mode of fopen always appends, regardless of any seeking you do afterward. You want to open the file with "w+b" for write/update access in binary. You have to use binary because text doesn't allow arbitrary seeking like you're trying to do.

You may also want to read up on how file streams work in C...

Narue 5,707 Bad Cop Team Colleague

nightwishmaster hasn't annoyed me yet. :)

Narue 5,707 Bad Cop Team Colleague

>i wanted to know to rectify the bugs in the present logic.
Okay, look at the code:

*(char *)(temp->data+i) = *(char *)(data + i);

Pointers to void have no size, therefore they cannot be scaled. You need to cast a pointer to void to a pointer to something else first, then scale the result and finally dereference:

cast:    (char*)temp->data      =   (char*)data
scale:  (                  + i)    (            + i)
deref: *                          *
final: *((char*)temp->data + i) = *((char*)data + i);

>And memcpy will be not working with strings as input.
Don't make me beat you with the grammar bat. memcpy works just as well with non-string data as it does with string data. Whatever you pass it is converted to a pointer to void, then treated as an array of unsigned char. That's why you pass a byte count rather than an item count as the last argument.

Narue 5,707 Bad Cop Team Colleague

One word: memcpy.

Narue 5,707 Bad Cop Team Colleague

>Google nither helped.
I get the feeling you didn't look very hard. Have you considered recursion? What about goto? Neither of those are considered to be loop constructs.

Narue 5,707 Bad Cop Team Colleague

>A friend gave me those questions but up till now i have not been able to do them..!!
Is your "friend" a teacher who teaches C and who's class you happen to be in?

Narue 5,707 Bad Cop Team Colleague

>yech, that looks sloppy, the indenting looks better in the IDE.
The closing tag for code uses a forward slash rather than a backslash. There's an obvious watermark in the post editor window that shows you exactly how to do it, so you really have no excuses.

Narue 5,707 Bad Cop Team Colleague

>arr = arr + arr[9-i] ;
>arr[9-i] = arr - arr[9-i] ;
>arr = arr - arr[9-i]
That's clever and braindead at the same time. Unless of course you didn't discover that solution, in which case it's just braindead.

Narue 5,707 Bad Cop Team Colleague

>what compiler do you suggest I ought to switch to?
Dev-C++ is usually a good choice.

Narue 5,707 Bad Cop Team Colleague

>You do realise that in C++, the main function, when an integer, expects a return value.
As a matter of fact, I'm quite familiar with that rule and all of the details that go along with it. Are you?

>So you shouldn't snip off the "return 0;" part.
In standard C++, if you fall off the end of the main function, 0 is returned implicitly. When I'm writing pre-standard C++, the rules for C89 apply and you're correct. But I'm not, so you're not. I would appreciate not being incorrectly corrected, so you would best do your research before asuming that I've made a mistake.

>If you don't want to return a value in main(), declare main() as void
This proves that you're not yet qualified to correct me on technical details of the C++ standard. void main is:

1) Non-portable on a hosted implementation that explicitly allows it.
2) Undefined on a hosted implementation that does not allow it.

At least one very common implementation doesn't allow void main, so your suggestion is very poor. Even on implementations that allow it, void main buys you *nothing*, especially in standard C++ where it doesn't even save you keystrokes.

>int main(void)
This is also a matter of style. C++ doesn't require empty parameter lists to be designated by void.

>void main() is never ever acceptable
It's perfectly acceptable on a freestanding implementation. The rules we refer to when talking …

bumsfeld commented: That is what I am learning in my courses. +1
Narue 5,707 Bad Cop Team Colleague

>That would mean the answer would be b.
No, the answer is d. There's no question about it since the inner loop you posted relies on N, not the value of the outer loop counter.

Now, if you're talking about counter2 being set to counter1 and using it as N, the answer would still be d because Big-O is an upper bound. For example:

for ( int i = 0; i < 10; i++ ) {
  for ( int j = i; j >= 0; j-- )
    ;
}

When i is 9 then j runs the full length of the outer loop, which is O(N). Since the outer loop is O(N), that gives you O(N^2). If you use O(N) as the upper bound, you've basically lied about your algorithm even though when i is 0, the inner loop isn't ten iterations. Even if it's for one iteration of the outer loop, the upper bound of the algorithm is O(N^2).

If you're really interested in being precise, you can work out a detailed analysis based on the increasing inner loop iterations. But that's not always worth it, and certainly not for this question.

>Same thing with this problem.
This is another form of the example I just gave.

Narue 5,707 Bad Cop Team Colleague

>Erm, but then I can't see that pretty little, is it a celtic symbol, which
>follows me everywhere I go in the background.
Bummer. When I get complaints that the background is more interesting than the content, I'll look into changing it. ;)

>Anything other than brown perhaps.
My recommendation is that you check your gamma settings. The background color is closer to pink than brown. :)

Narue 5,707 Bad Cop Team Colleague

>Erm, your webpage doesn't display properly when viewed at a lower resolution...
It handles the de facto standard resolution of 800x600 when you hide the navigation bar. If your resolution is smaller than that, and you can't go higher, you're SOL until I decide to redesign.

>also the browny interface blows...
It's generally good practice to offer an alternative solution when you completely dismiss someone else's design choices.

>That website is really helpful for more than just a heap sort.
That's what I was going for. :) Now if only I had enough free time to actually write everything that I have floating around in my head...

Narue 5,707 Bad Cop Team Colleague

>but seems like there is a flaw somewhere
There is, and it's frustrating how the same incorrect algorithm is given so often by incompetent teachers. Here, read this. It's in C, but the code is similar enough and the principles all apply for Java.

Narue 5,707 Bad Cop Team Colleague

strcmp takes C-style strings, not C++ string objects. The string class has overloaded the relational operators, so you can use < and > to compare them. But if you have your heart set on strcmp, you can do this:

x = strcmp(word1.c_str(), word2.c_str());
Narue 5,707 Bad Cop Team Colleague

Now, now, children. Don't make me separate you. :rolleyes:

ahluka, you haven't earned the right to your attitude, so stuff it or I'll have a field day moderating your posts. If you want us to tolerate some lip, show that you're worth it. And yes, I'm familiar with your performance on other forums.

iamthwee, the link was relevant, even though it reeked of spam and was borderline on advertising. Yes, he's entertaining, but please don't feed the trolls.

Narue 5,707 Bad Cop Team Colleague

>whats the relationship between vectors in c++ and physics?
None that you need to worry about unless you're simulating a physics vector. A C++ vector is basically the same as an array, except with a pretty interface.

Narue 5,707 Bad Cop Team Colleague

Even the worst book on C++ will will cover such topics as arrays, and we don't particularly enjoy explaining things that are covered in great detail in *every* available reference.

For a quick overview, try surfing over to wikipedia and search for arrays.

Narue 5,707 Bad Cop Team Colleague

>also when you said pure did u mean so i cant use javascript
Javascript is a separate language from HTML. By 'pure HTML' I mean no tools or languages that extend the power of HTML. Just the HTML 4.0 specification and a conforming browser.

>other wise u r corect i canot do it with html
Bingo. :)

>but i can do it with javascript using html
Javascript is a turing complete programming language. Theoretically it can do anything.

Narue 5,707 Bad Cop Team Colleague

>The << and >> operators are not interchangeable. You also have a few other syntax errors and unnecessary stuff that can be removed:

#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
  int a,b,k;
  cout<<"enter 1,2,or 3";
  cin>>k;
  cout<<"enter 1,2,or 3";
  cin>>b;
  a=k+b;
  cout<<endl<<a;
  system ("pause");
}
Narue 5,707 Bad Cop Team Colleague

>ok what type of data do u want it to be?
Integers will be fine. And a table doesn't count as it's a formatting directive for text, not a data structure, if that's what you were thinking. :)

Narue 5,707 Bad Cop Team Colleague

>whats a data structure?
Array, linked list, binary search tree. Any structured collection of data.

Narue 5,707 Bad Cop Team Colleague

>tecknickly it is a programing launguage
No, it's not, by any definition.

>but come on it does the same function any other lauguange does
Really? Do this with HTML:

for ( int i = 0; i < 10; i++ )
  cout<<"Repeat\n";

Give me a data structure, even a simple one, in pure HTML. Two *primary* requirements for any programming language are the manipulation of data, and control of the flow of execution. HTML can do neither because it's not designed to be a programming language. HTML is a file format that external programs (browsers) use to determine the appearance of text.

Narue 5,707 Bad Cop Team Colleague

>but for me i am an html person so it is easy the other way for me but i see your point.
Well, HTML technically isn't a programming language, so now you're learning the real thing. :)

>is it posible for me to nip my own threads?
No, only forum moderators can lock threads. You can, however, mark your own thread as solved when you feel your question has been answered to your satisfaction. The option is just above the first post, to the right of the Advanced Reply button.

Narue 5,707 Bad Cop Team Colleague

>{g=0}
You need a terminating semicolon:

{g=0;}

These things are easier to see if you separate the statements from the brackets and use whitespace between tokens consistently:

if (g == 3282)
{
  g = k;
}
else
{
  g = 0;
}
Narue 5,707 Bad Cop Team Colleague

>whoa narue thats cool that there is an endif
Well, not in C++. But you can fake it with macros if you're a sadist:

#define then {
#define endif }

if ( a == b ) then
  <statements>
endif

But, don't do that. You won't be able to show your code to very many people before they lynch you. ;)

Narue 5,707 Bad Cop Team Colleague

>how do u write this if then statment but in c++ if g=3282 then g=k;
Don't you have a book? Learning a language is extremely difficult without a proper reference available.

>to bad there wasnt a then like there is an else in c++
Why? "then" is typically used as a language defined parsing helper for the compiler, like the parentheses in C++. When the parser finds "if", it processes a conditional test until it finds the corresponding "then". Compare:

if a = b then
  <statements>
endif
if ( a == b ) {
  <statements>
}

It's pretty obvious that this framework is already in place in C++; it just doesn't use the same tokens.

Now, an interesting tidbit that's largely unrelated is that "then" isn't always used like that. In a stack based language like FORTH, the parsing trick isn't needed, and "then" is used as a conditional terminator (what other languages use "endif" for):

a b = if
  <statements>
then
Narue 5,707 Bad Cop Team Colleague

First, format your code so that it's readable. Then post the code using code tags so that the formatting isn't lost. Finally, give way more information than "it doesn't work" and "seg fault". Despite how it may seem, we're not here to be your testers and debuggers. Please consider that many of us are professionals that are busy with our own problems, and you need to help us to help you.

That said, a segmentation fault is caused by accessing memory outside of your address space. With a hash table, and it looks like you aren't using separate chaining, that means you've got an invalid index somewhere.

Narue 5,707 Bad Cop Team Colleague

>I need to find out if the length of the integer (string) is less than 5 digits.
Um...

if ( s.length() >= 5 ) {
  // Proceed
}
Narue 5,707 Bad Cop Team Colleague

When you say something isn't working, it suggests that the code even compiles, which it doesn't. Does this work the way you expect?

#include <iostream>

using namespace std;

int main()
{
  int option;
  do
  {
    cout << "             WYZ Company\n\n";
    cout << "          1 - for loop\n\n";
    cout << "          2 - while loop\n\n";
    cout << "          3 - do while loop\n\n";
    cout << "          4 - stuff01\n\n";
    cout << "          5 - stuff02\n\n";
    cout << "          6 - exit\n\n";
    cout << "enter desired processing option here: [ ]\b\b";

    cin >> option;

    //display menu
    switch(option)
    {
    case 1: cout << "you entered option 1\n";
      break;
    case 2: cout << "you entered option 2\n";
      //use while loop
      break;
    case 3: cout << "you entered option 3\n";
      //use do/while loop
      break;
    case 6: cout << "you entered option 6\n";
      //exit
      break;
    default: cout << "wrong code dummy\n";
      //output information to user
      break;
    } //end switch
  }while (option != 6);
  system("pause");   
}
Narue 5,707 Bad Cop Team Colleague

>the actual function i'm trying to get is
That's not helpful and you're not listening to my question. Post the declarations of the relevant variables.

Narue 5,707 Bad Cop Team Colleague

>the solution i need to obtain is
>sum = A[j] + B;
What are the types of A, B, and sum? I really don't see what the problem is unless A[j] and B are incompatible for addition, or sum can't hold a value of the result.

Narue 5,707 Bad Cop Team Colleague

You can play games with modular arithmetic to avoid adding another variable, but sometimes it's just easier to count how many numbers you've printed. When you get to 3, print a newline and reset the counter:

#include <iostream>
using namespace std;

int main()
{
  int x, n = 0;

  cout<<"Numbers between 5 and 12 (3 numbers per line)are:\n";

  for ( x = 5; x <= 12; x++ )
  {
    cout<< x <<" ";

    if ( ++n == 3 ) {
      cout<<'\n';
      n = 0;
    }
  }

  cout<<"\n\n";
}
Narue 5,707 Bad Cop Team Colleague

>cin.sync(); // purge any \n
This non-portable. From a standard perspective, it's also nonsensical for sync to discard the contents of the buffer. I've discussed it at length here.

cin.ignore ( 1024, '\n' );
cin.get(); // wait

Magic numbers should be avoided:

#include <ios>
#include <limits>

cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
cin.get(); // Wait
cin.get(); // trap loose \n
cin.get(); // wait

This only works if the only thing left in the stream is a newline.

cout << "Press any key to continue ..."; 
string z; 
getline(cin,z);

That's seriously overkill, and the prompt is misleading because getline is line oriented. You can hit any key, but unless that key is Enter, nothing will happen.

>I am a little skittish posting in the C++ forum, since I have been kicked out of here unceremoniously in the past.
I don't recall you being "kicked out". Can you link to the offending thread?

Narue 5,707 Bad Cop Team Colleague

If I understand correctly, you're doing this:

C:\>Test Tekstfile

Try this instead:

C:\>Test Tekstfile.txt
Narue 5,707 Bad Cop Team Colleague

><snip angsty whining> I am supposed to read numbers out
>of a file piano.data and put the results into report.out.
How are the results to be formatted? Give us an example run of the program.

>The piano file is structured like this
Exactly like that? Or are you adding your own commentary? The difference is in how you parse the data, and that's a pretty big difference.

Narue 5,707 Bad Cop Team Colleague

>error LNK2019: unresolved external symbol _main referenced in function
You're using a console application?

Narue 5,707 Bad Cop Team Colleague

LPCWSTR is a wide string type and a string literal is a narrow string type. The two aren't compatible. You can fix it in a number of ways. First, you can make the string wide by prefixing it with L, or you can use the _TEXT macro provided by the Win32 API for selecting the right string width to match your settings. Or you can use MessageBoxA directly instead of using MessageBox as a "smart" entry point.

>Could anyone tell me why it works in the one, but not in the other
MessageBox calls either MessageBoxA or MessageBoxW depending on the need to use 1 or 2 byte character sizes. I'm inclined to think that your Visual Studio setup is conflicting with your needs somewhere while Dev-C++'s setup isn't.

Narue 5,707 Bad Cop Team Colleague

>Is there still room more major break throughs and advances in computers?
Of course. We've only scratched the surface in the field of computing.

>i just like to think of these questions
Take some time to think of the answers as well, they're usually pretty intuitive.

Narue 5,707 Bad Cop Team Colleague

>I did some of that in a Bioinformatics course cotaught
>between a Comp Sci professor and Bio professor.
I stand corrected.

>What i meant is that computers might one day go down
Barring some catastrophic event that either completely destroys all computers and the information required to make them, kills all of the people who know how to make them, and basically causes the human race to become extinct, or creates a worldwide EMP that makes it impossible to fix things and throws us back into the stone age, I don't see computers going down one day.

They permeate too much of our society for anything short of complete devastation to put an end to them. And in such a case, you really wouldn't care much about your education, would you? ;)

>and if you study CS, will you definetly be working with a computer or software for a job?
Not necessarily. You'd be surprised how many people don't work in the field that they studied for in college.

Narue 5,707 Bad Cop Team Colleague

>When you said that most people learn things outside of class, what do you mean?
Let's take a simple example: a linked list. A class can teach you the concept of a linked list, as well as basic implementation. When and where to use a linked list comes intuitively through experience in real world projects. Little tricks to improve a linked list are gathered over the years by looking over the shoulders of better programmers. In the end, the class taught you very little compared to your out of class experience.

>will CS let you see other aspects of science as well?
Well, you won't learn about marine biology in a CS course, if that's what you mean. ;) But a lot of fields come together in CS, like mathematics, physics, and electrical engineering. You won't get the same intense focus on any one of them, but a general taste of different things is expected.

Narue 5,707 Bad Cop Team Colleague

>actually if u read y n(and) why they are heard same!!!
Are they? Perhaps in English, but in Japanese "n" is very nasal to the point of being completely voiceless. The sound is very unlike the English word "and". What about "u"? Same thing. In Japanese, "u" is pronounced "oo", which is very different from the English word "you". What about "y"? I don't even have to leave Japanese to tell you that there is no phoneme that matches "y" to the same sound as the English word "why".

That's one non-English example that will cause native speakers to have fits when trying to understand your silly abbreviations. Pick any other language and you'll see similar situations. This isn't text messaging or chat and you can afford to take your time.

>Do give your helpful replies later also...
You must have missed the helpful replies that have already answered your question fully. Yes, <iostream> is correct, <iostream.h> is not, but your compiler is too old. Get a new compiler or realize that you're not really learning C++.