Narue 5,707 Bad Cop Team Colleague

>I dnt want to purchase a book as yet.
Then you're already walking on thin ice.

>Can any one refere me to a site from which I will be able to learn the basics relatively quick.
Yes. There's only one site that offers basic C++ tutorials that I'll recommend (until I write my own, of course), and that site is this one.

Dave Sinkula commented: Hm. Something new to check out. Thanks. +11
Narue 5,707 Bad Cop Team Colleague

Look here and try to find an overload of replace that takes two arguments.

Narue 5,707 Bad Cop Team Colleague

>I've completed programs with the use of the getline function and it works ok.
I bet those programs didn't try to pass a double into getline instead of a string:

double number;//the grades as in the infile

while (getline(infile,number,'\n')

There are other problems too:

>int num;//number of grades
>int Hi;//highest test grade
>int Low;//lowest test grade
You use these but never give them a value.

>sting stat;
Sting? Perhaps you meant to type string.

else if (number>average)
	{
	cout<<number<<setw(5)<<" Above"<<endl;
}

You forgot to close the block on that else if statement.

Narue 5,707 Bad Cop Team Colleague

>can anybody help me ?
If by "help" you mean "write it for me", no. Nobody will help you. If you mean help in the more traditional sense of you do the majority of the work and we give you hints and tips, and suggest ways to improve your solution, yes. We'll be happy to help. But as it is, you don't have any code and haven't told us how you plan to write this function, so there's nothing to help with.

Narue 5,707 Bad Cop Team Colleague

>so the question is how can the compiler think that this is function
This is how it would be parsed:

deque<int> c ( istream_iterator<int> cin, istream_iterator<int> );

That looks exactly lot like a function declaration, doesn't it?

Narue 5,707 Bad Cop Team Colleague

>I know that you need to all the same function (one you declare)
>again and again to get the result.
Yes, either directly or indirectly. Otherwise it's not recursion. By directly, the a function calls itself without any intervening calls. Indirectly is when a function calls other functions that eventually call it again.

Narue 5,707 Bad Cop Team Colleague

My thought process was that I could start the loops at the beginning and the end of the string and then swap the two characters. Then, I could increase the iteration of the beginning by one and decrease the iteration of the end by one, and the repeat the swap.

Yep, that's the way to do it. Usually you'd use a single loop though:

int start = 0;
int end = n - 1;

while ( start < end ) {
  std::swap ( a[start], a[end] );
  ++start;
  --end;
}

>If you guys have any suggestions or advice I would really appreciate it.
I only have one complaint. The algorithm you've described and implemented isn't recursive at all. Are you sure you're doing what you need to be doing?

Narue 5,707 Bad Cop Team Colleague

>tell me the other cases
It depends on the stream. In the case of cout, you can expect it to be flushed when the program ends.

>then buffer should not get flushed until "saturated "
That's a reasonable assumption.

>and what if i increase the capacity of buffer !!!?
Then it will take longer to get flushed, perhaps? This isn't rocket science.

Narue 5,707 Bad Cop Team Colleague

>then is it not possible to display output without using 'flush'
What in the world are you talking about? The only way to send output to the destination is to flush the buffer, and the buffer gets flushed automatically according to certain rules. You only need to call the flush member function when the automatic flushing isn't good enough.

>And to what extent can i increase the capacity of buffer?
You can replace the buffer with your own, thus the extent is limitless.

Narue 5,707 Bad Cop Team Colleague

>you must read something before the loop test, then read
>that element as the last action in your loop body, similar to:
What a waste of effort. How about, instead of having to figure out the order of operations and throw in redundant code to make it work, you just did this:

while ( getline ( myfile, identifier ) ) {
  // Get other lines of input
  // Process data
}

Or is that too simple for you? I understand that some people like to make everything complicated for no reason at all.

Narue 5,707 Bad Cop Team Colleague

>but using cout or any object of ofstream also makes the data to be outputted
You're mixing things up. Any object derived from ostream contains a buffer. It's this buffer that "makes the data to be outputted", and when it sends characters from the buffer to the destination (the destination could be a file, your monitor, or something else), we call this a flush. Now, the buffer flushes itself periodically without intervention from you (such as when it fills up or you request input from a tied stream). However, if you want the buffer to flush itself outside of those times, the flush member function is there so that you can force a flush.

So the difference is that flush gives you more control over when the buffer is flushed, rather than waiting until the implementation is ready.

Narue 5,707 Bad Cop Team Colleague

>first i need to know if my implementation to the function is right
Does it compile? Does it run? Does it produce the results you expect? Do you get the expected results for a large number of test cases? Those are the first questions you ask yourself to see if the implementation is correct.

>void main()
main returns int, always. Don't listen to anyone who tells you otherwise.

Narue 5,707 Bad Cop Team Colleague

Could you not post everything in bold text, please?

>i already know what you said what i need to know if
>there is any difference in writing the implementation
There isn't. In fact, you don't even need two classes for this as the declaration of an object of String will handle the constness for you. Of course, you can't define two classes of the same name anyway, so the point is moot.

Example:

class MyString{
  char *cp; // pointer to the first element
  int Alng; // the N# of the elements in the array [max N# of char is Alng -1 ]
public:
  MyString(const char *str, int alng) ;
  ~MyString();
  const char* getstr()const{ return cp;}
};

MyString::MyString(const char *str,int alng)
{
  cp = new char[alng + 1];
  for ( char *p = cp; *str != '\0'; ++p, ++str )
    *p = *str;
  Alng = alng;
}
MyString::~MyString()
{
  delete[] cp;
}

>also it's fine with me that your not arabian nor a girl
He was implying that we don't care what your nationality or gender are.

Narue 5,707 Bad Cop Team Colleague

>Why doesn't it look good?
Because a lot of us visit most of those forums, and seeing an identical thread on each one reeks of spamming and trolling for answers.

>I don't see what it matters where else I get answers.
It doesn't matter. What matters is that by asking us, then asking another forum, you're basically saying that you don't trust our answers. On top of being insulted like that, those of us that visit all of the forums in question are going to be irritated by having to pick which forum to help you on for maximum effect. That's a lot of work, and while I can't speak for Salem, I'm not willing to go to that kind of effort just to help some faceless net junkie. Also keep in mind that the most qualified helpers are going to be members of most, if not all, of those forums. By alienating us, you risk losing the highest quality answers.

>If you really feel that I'm acting like a spammer then I'll leave and not come back.
Okay. We don't care if you stay or go. That's completely your decision, regardless of how much you try to focus the blame on other people. Throwing out an ultimatum just makes you look like you're starved for attention.

>I don't have time for this drama. I never thought I'd catch this kind of flak for asking for help.
Salem is trying to help you. …

Narue 5,707 Bad Cop Team Colleague

>I've tried so hard to do it but I couldn't
I don't believe you. Post your attempts and describe how they didn't work to prove that you've tried "so hard".

>I have to send it to my professor tonight so please HELP
We generally don't care how much of a hurry you're in, so don't appeal to our sense of urgency.

Narue 5,707 Bad Cop Team Colleague

>error C2065: 'numz' : undeclared identifier
Your code looks fine. Did you make any changes from what was posted originally?

>warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
You can ignore this, but it's a good practice to match the type of whatever values you're getting. In this case, the return type of string::length is string::size_type, which in your case equates to std::size_t. This would be better:

std::string::size_type numz = sentence.length();
Narue 5,707 Bad Cop Team Colleague

>Am i somehow telling it to do that or is that correct??
You're probably telling it to do that. Most likely you neglected to remove the input call outside of the loop, so your broken code would look something like this:

inf>> in;

while ( inf>> in ) {
  x = log10 ( in ) + 1;
  outf<<"digits = "<< x <<'\n';
}
Narue 5,707 Bad Cop Team Colleague

>how do you tell it to proceed to the next number
The same way you told it to process the first number, just do it inside the loop rather than outside:

while ( inf>> in ) {
  x = log10 ( in ) + 1;
  outf<<"digits = "<< x <<'\n';
}

Because the >> operator returns the stream, and the stream has a conversion to something that can be tested for success or failure, you can use the entire operation as your loop condition.

Narue 5,707 Bad Cop Team Colleague

>void main (void) int main() . No excuses.

>while (in<2000000000 && in>-2000000000)
What requirement brought this about? Anyway, you only read one number and proceed to work only on that number. You need to read another number inside the loop.

Narue 5,707 Bad Cop Team Colleague

>A) is the way I used the string and new operator correct for this little program?
It looks fine, why do you ask?

>B) is this <bad Ptr> related to a bad Pointer and what does that mean?
It's just your debugger's way of saying that mName isn't ready to be used yet. If you get that after stepping over the line (where mName should be created and initialized), then you probably have an issue.

>C) I don't have to determine the sizeof this string?
Why should you? std::string is an object that manages the actual string for you. The memory grows to fit the size of the string automagically. If you had to manage the size, why use std::string instead of an array of char?

>oh yes, has the search function been altered on this forum?
Yes, it's gimped now. Completely useless if you want to do any kind of advanced searching. But it seems Dani isn't done upgrading the search feature, so perhaps it will be fixed in the near future.

Narue 5,707 Bad Cop Team Colleague

In the swap step, you're swapping with maxIndex when you should be swapping with index.

Narue 5,707 Bad Cop Team Colleague

Just like variables, functions have to be declared before you use them:

#include <iostream>

using namespace std;

float Omrekenen(float tempFahrenheit);

int main()
{
	float tempFahrenheit;
	float tempCelsius;
	float Omrekenen;

	cout << "Geef de temperatuur in Fahrenheit: ";
	cin >> tempFahrenheit;
	tempCelsius =Omrekenen(tempFahrenheit);
	cout << "\n Dit is de temperatuur in Celsius: ";
	cout << tempCelsius << endl;
	return 0;
}
float Omrekenen(float tempFahrenheit)
{
	float tempCelsius;
	tempCelsius = (tempFahrenheit - 32)*5/9;
	return tempCelsius;
}
Narue 5,707 Bad Cop Team Colleague

>%02.3f
The field width is the total number of printed characters, not the number of characters before the radix. Try "%06.3f" instead.

challarao commented: short and precise +1
Narue 5,707 Bad Cop Team Colleague

>Well, the day is still young.
This is true. Maybe TkTkorrovi will decide to come back later this evening. Or Mister C from cprogramming.com will make an appearance shortly and try to debate the intricacies of undefined behavior with me. But until then, you hold the crown.

>What makes you the expert and what stuff are you on?
The expert on what? Insulting technical professionals, Indians, and Chinese? Your statement lacked the detailed information necessary to keep it from being a bigoted flame.

>Why do you old folks always have to insult us young folks?
By young and old I'll assume you mean how long we've been on Daniweb. To answer that, I'm an equal opportunist. I'll insult whomever deserves it, regardless of seniority or station. Dani can verify that, as she's been on the receiving end of my sharp tongue once or twice.

>My point, why would an employer keep hiring folks at such inflated pay levels, if he/she
>can get the same job done for $5 an hour in India? Distance wouldn't mean much on the internet.
And what makes you the expert? Apparently you haven't ever done any research on the real costs of outsourcing and fell prey to the hype. The upfront cost is almost always obscene, and after a few years, the final savings aren't nearly what you're suggesting. Sure, there are savings if it's done right, but often companies end up losing those savings …

Lardmeister commented: MEAN COMMENTS +0
Duki commented: not that it counts anymore in the geek's lounge, but.... EQUALIZERRRR +4
Narue 5,707 Bad Cop Team Colleague

>In your present technical field you will always be just a
>peon competing with low paid labor from India or China.
This has to be the most ignorant comment I've seen all day, and I deal with some pretty ignorant folks.

Narue 5,707 Bad Cop Team Colleague

>In a scenario where you had to choose between Operating Systems and Computer
>Architecture, which would you have chosen keeping my field in mind?
It really depends on what the operating systems class covers. Most likely it's going to be steeped in theory and minute details of OS design and implementation. While these are interesting topics, they're probably not going to be practical for you. On the other hand, computer architecture is likely to cover fundamental concepts that every technical professional should know.

My advice would be the same as Duki's: Go with the databases class because it has the greatest chance of giving you something useful after you graduate. The second choice would be computer architecture because of the core concepts that you'll learn. For the field you're interested in, I don't think operating systems would be more than a dalliance.

Narue 5,707 Bad Cop Team Colleague

The only part of the code you posted that the warning makes sense on is:

!isdigit(array[i])

And a cast can fix that, because isdigit expects an unsigned char value or EOF:

!isdigit ( (unsigned char)array[i] );

Post a more complete example that exhibits the problem, please.

Narue 5,707 Bad Cop Team Colleague

>That's a pointer?
It's a pointer-like object.

>I don't get it..... we haven't went over pointers yet
Then do this:

void display() const
{
  std::vector<Pizza>::size_type i;

  for ( i = 0; i < _pizzas.size(); i++ )
    _pizzas[i].display();
}
Narue 5,707 Bad Cop Team Colleague

>but how do classes access variables in other classes?
There are

1) Make the data members public, then anyone can access them:

class test {
public:
  int foo;
};

int main()
{
  test t;
  t.foo = 123;
}

2) Make the data members protected, then derived classes can access them:

class test {
protected:
  int foo;
};

class derived: public test {
public:
  void bar() { foo = 123; }
};

3) Make the function or class that accesses a data member a friend of the class:

class test {
  friend void bar ( test& t );
  friend class baz;
private:
  int foo;
};

void bar ( test& t )
{
  t.foo = 123;
}

class baz {
public:
  void blah ( test& t ) { t.foo = 123; }
};

4) Provide a public or protected member function that accesses the data member:

class test {
private:
  int foo;
public:
  int get_foo() { return foo; }
  void set_foo ( int value ) { foo = value; }
};

int main()
{
  test t;

  t.set_foo ( 123 );
  int bar = t.get_foo();
}

>I am completely lost on how to write the Orders class so that I can output the Pizza information.
Okay, a pizza contains all of its information, right? And an order is just a collection of pizzas. So what you want to do is have the Pizza class provide a way to print or return its information so that the …

Duki commented: great explanation +4
Narue 5,707 Bad Cop Team Colleague

>Or am I utterly confused
You're utterly confused. All of the things that cout can print have an operator<< defined for them. When you want to use this syntax to print your own custom classes:

cout<< my_object <<endl;

You have to overload the operator<< function for your class. The operator<< function should look like this for any given class and output stream:

[I]<output stream>[/I]& operator<< ( [I]<output stream>[/I]& out, const [I]<your class>[/I]& obj );

However, if you want the operator to have access to any private or protected members of the class, it has to be a friend of the class as well.

>friend cout << ( ostream & out , const Time & t )
I don't even know what this is supposed to be.

>none of that^ makes since to me. =(
It's the same thing, just more flexible because you're not restricted to std::ostream objects. For example, you can use both cout and wcout where the example that uses std::ostream can only use cout.

Narue 5,707 Bad Cop Team Colleague

>cout << MyPizza.size << endl
No, size is a private data member. Unless the outOrders function is a friend of the Pizza class or a member function of a class which is a friend of the Pizza class, you don't have access to the private data. However, if you define the operator as I showed, you can do this:

cout<< MyPizza <<'\n';

And all of the private data you choose to output in the overloaded operator will be sent to cout in the way you format it, followed by a newline. Another example, even simpler:

#include <iostream>
#include <ostream>

class Time {
  int _minutes;
  int _seconds;
  bool _is_am;
public:
  Time ( int minutes, int seconds, int is_am )
    : _minutes ( minutes ), _seconds ( seconds ), _is_am ( is_am )
  {}

  friend std::ostream& operator<< ( std::ostream& out, const Time& t );
};

std::ostream& operator<< ( std::ostream& out, const Time& t )
{
  return out<< t._minutes <<':'<< t._seconds <<' '
    << ( t._is_am ? "AM" : "PM" );
}

int main()
{
  Time now ( 9, 55, true );

  std::cout<<"The time is "<< now <<". Isn't that nifty.\n";
}
Narue 5,707 Bad Cop Team Colleague

>So how would I access the Pizza data to output it?
Probably define a member function or overloaded << operator that performs the output. In the code you posted, the Pizza class doesn't provide any way to get at the data. For example (keeping it simple):

class Pizza
{
public:
    void setCheeseToppings ( int ) ;
    void setPepperoniToppings ( int ) ;
    void setSize ( string ) ;
    void setType ( string ) ;

    template <typename CharT>
    friend std::basic_ostream<CharT>& operator<< (
      std::basic_ostream<CharT>& out, const Pizza& pie );
private:
    int cheeseTop ;
    int pepperoniTop ;
    string size;
    string type;
} ;

template <typename CharT>
std::basic_ostream<CharT>& operator<< (
  std::basic_ostream<CharT>& out, const Pizza& pie )
{
  return out<<"Cheese: "<< ( cheeseTop ? "Yes" : "No" );
}
Narue 5,707 Bad Cop Team Colleague

>Is this encoding designed to hide the programming?
Compiled programs aren't like HTML. The source code is lost during compilation unless the executable format supports metadata that can reconstruct it, like .NET. Those symbols you saw were the text editor's attempt to turn binary into printable characters.

>How can I determine the programming language of an .exe file?
You can disassemble the executable and reconstruct the design of the program. From that it's sometimes possible to infer the original language that it was written in. However, this requires a great deal of experience and talent in reverse engineering, as well as intimacy with assembly language and any of the possible languages that the program could have been written in.

Short answer: You can't.

>And how can I view it?
This is a more plausible question because you can disassemble the executable and read the assembly, but if you have to ask how it's done, you're probably not capable of doing it at your current level.

Narue 5,707 Bad Cop Team Colleague

>If any mod reads it and is in the mood to change my code adding the & I would be very grateful.
It's generally better to leave the code as you originally posted it so that any replies remain relevant. If you have a new version of the code, create a new post in the thread with the updated source.

Narue 5,707 Bad Cop Team Colleague

When you want help with your code after making changes, it's customary to post the latest version. Otherwise it's extremely difficult to help you effectively.

Narue 5,707 Bad Cop Team Colleague

>mName = c1 + c2 + c3 ;
This doesn't do what you think it does. c1, c2, and c3 are all integral values, so the + operator performs integral addition, not string concatenation. Why not just read the input into a string from the start?

void setMbyN ( istream & is )
{
    const string months[] = {
      "jan", "feb", "mar", "apr", "may", "jun",
      "jul", "aug", "sep", "oct", "nov", "dec"
    };

    string mName;

    is>> setw ( 3 ) >> mName;

    for ( string::size_type i = 0; i < mName.size(); i++ )
      mName[i] = tolower ( mName[i] );

    month = 0;

    for ( size_t i = 0; i < 12; i++ ) {
      if ( months[i] == mName ) {
        month = i + 1;
        break;
      }
    }

    if ( month == 0 )
      throw runtime_error ( "Invalid month" );
}
Duki commented: great function! worked excellent! +4
Narue 5,707 Bad Cop Team Colleague

>Or would that not work?
It wouldn't work for the same reason, assuming setMbyN is a member function and not an object.

Narue 5,707 Bad Cop Team Colleague

>In my book it gives the following example
Okay, I'm thinking you're a tad confused about how initializers work. This is correct use of an initializer:

class foo {
  int bar;
public:
  foo(): bar ( 12345 ) {}
};

bar isn't a member function at all, it's an object. It looks like you're calling a function called bar, but the initializer is essentially calling bar's constructor with the value 12345. It works the same way as the following except the constructor is implicit because int is a built-in type:

class bar {
public:
  bar ( int init ) {}
};

class foo {
  bar b;
public:
  foo(): b ( 12345 ) {}
};

In the sample you provided, accountDollars and accountCents are both objects, most likely integers, like this:

class BankAccount {
  int accountDollars;
  int accountCents;
  double accountRate;
public:
  BankAccount ( double balance, double rate );
};

BankAccount::BankAccount ( double balance, double rate )
  : accountDollars ( 0 ), accountCents ( 0 )
{
  accountRate = rate;
}

Now, you can use the result of a function to initialize an object, and your sample does just that. Probably something like this:

#include <cmath>

class BankAccount {
  int accountDollars;
  int accountCents;
  double accountRate;
public:
  BankAccount ( double balance, double rate );
private:
  static int dollarsPart ( double amount );
  static int centsPart ( double amount );
};

BankAccount::BankAccount ( double balance, double rate )
  : accountDollars ( dollarsPart ( balance ) ),
  accountCents ( centsPart ( …
Narue 5,707 Bad Cop Team Colleague

>for someone who understand ctors very well, perhaps.
Perhaps, but somehow I doubt it. You're told exactly what name is causing the problem and exactly where it is (the initializer list). Since there's only one thing in the initializer list, it's pretty obvious that it shouldn't be there whether you understand constructors or not.

>So how would I modify it from here:

class Month
{
public:
    Month ( char a, char b, char c )
    {
        setMbyNcheck ( a , b , c ) ;
    }
    Month ( int i )
    {
        setMcheck ( i ) ;
    }
    Month ( ) ;

    void setMbyN ( istream & is ) ;
    void setM ( int ) ;
    void outMbyN ( ) ;
    void outM ( ) ;
    Month nextMon ( ) ;
private:
    void setMbyNcheck ( char , char , char ) ;
    void setMcheck ( int ) ;
    int month ;
} ;
Narue 5,707 Bad Cop Team Colleague

>i don't understand
What's there not to understand? You can't do this:

class foo {
public:
  foo(): bar() {}
  void bar() {}
};

You fix it by taking bar out of the initializer list and putting it in the constructor body:

class foo {
public:
  foo()
  {
    bar();
  }
  void bar() {}
};

The error is hardly cryptic.

Narue 5,707 Bad Cop Team Colleague
Narue 5,707 Bad Cop Team Colleague

You had quite a few transcription errors. In other words, unless the book is absolutely horrid, you introduced syntax errors on your own when typing the code in. I've cleaned it up for you and fixed the syntax errors. Don't expect me to do it again:

#pragma once

namespace speedgame {
  using namespace System;
  using namespace System::ComponentModel;
  using namespace System::Collections;
  using namespace System::Windows::Forms;
  using namespace System::Data;
  using namespace System::Drawing;

  /// <summary>
  /// Summary for Form1
  ///
  /// WARNING: If you change the name of this class, you will need to change the
  ///          'Resource File Name' property for the managed resource compiler tool
  ///          associated with all .resx files this class depends on.  Otherwise,
  ///          the designers will not be able to interact properly with localized
  ///          resources associated with this form.
  /// </summary>
  public ref class Form1: public System::Windows::Forms::Form {
  public:
    Form1()
    {
      InitializeComponent();
    }

  protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Form1()
    {
      if ( components )
        delete components;
    }

  private:
    System::Windows::Forms::ToolTip^  tipControl;
    System::Windows::Forms::Timer^  tmrControl;
    System::Windows::Forms::TextBox^  txtDisplay;
    System::Windows::Forms::TextBox^  txtEntry;
    System::Windows::Forms::Label^  lblInstructions;
    System::Windows::Forms::Label^  lblSourceText;
    System::Windows::Forms::Label^  lblEntryText;
    System::Windows::Forms::StatusStrip^  stsControl;
    System::Windows::Forms::ToolStripStatusLabel^  stsLabel;
    System::Windows::Forms::Button^  btnGo;
    System::Windows::Forms::Button^  btnDone;
    System::Windows::Forms::Button^  btnExit;

    System::ComponentModel::IContainer^  components;

    Int16 intWrong; //Tracks number of strikes
    Int16 intCount; //Tracks number of tries
    Int16 intTimer; //Tracks elapsed time

#pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
      this->components = (gcnew System::ComponentModel::Container()); …
Narue 5,707 Bad Cop Team Colleague

>can someone please help?!
Two very qualified people have already given you good advice. Are you ignoring their suggestions and hoping that someone does all of the work for you? If not, explain what you've done to troubleshoot and how it didn't work.

Narue 5,707 Bad Cop Team Colleague

You're beginning to annoy me with this "Woe is me! I broke the rules and got punished!" attitude. Get over yourself, you're no different from any other rule breaker.

Narue 5,707 Bad Cop Team Colleague

Your post was edited by an objective third party. In other words, you were at fault, and the verbal abuse was snipped from your attacks. If you keep it civil, you won't be censored. But if you want to be childish about it, I'll be happy to close this thread.

TkTkorrovi commented: Please leave me alone, and stop offending me +0
Narue 5,707 Bad Cop Team Colleague

I don't think anyone will be interested in joining forces with a person who throws a tantrum when things don't go his way. Perhaps you should learn what I teach rather than prattling on and on about how you've been "violated". :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

>If I were to do it, I would need to include "game.h" in enemy.c
>as well seeing as I'm using the variable enemyPosX from it?
I would move everything that pertains to enemies into enemy.h. Then you would need to include enemy.h in game.c, which is a smidge more intuitive.

Narue 5,707 Bad Cop Team Colleague

>The program works but I'm wondering if I should make a new file called enemy.h
You can if you'd like. I don't see any benefit for it at this point though.

Narue 5,707 Bad Cop Team Colleague

>One should understand that it's not possible to implement
>standard input with line buffering without the canonical mode.
Incorrect. The C standard requires nothing of the sort. If you're going to spar with me on matters of the language standard, at least know what you're talking about.

>Look, you even didn't say that my explanation is wrong
Quite right, because your explanation was fine. However, it was also quite useless to someone who isn't familiar with the idiom because you failed to describe how it works.

>This is the difference which i talked about, and this is an
>objective fact, free of any intentions which you tried to ascribe to me.
Indeed? And what, pray tell does any of this have to do with producing the effect of getch on Linux? I don't have a problem with your opinions, but I do have a problem with your opinions diminishing the value of any legitimate technical help you attempt to provide.

Narue 5,707 Bad Cop Team Colleague

>By default, the standard input in c is in the canonical mode, which means that all input is
>line buffered and the line would be received only after the linefeed.
That's not how buffering in C works. You're confused about the connection between a command shell and a C program. Canonical mode in a command shell is separate in that the shell's input buffer collects input and allows editing of that input before passing it on to the running program. Non-canonical mode sends characters directly to the running program as they're received by the shell. The running program doesn't know or care about the shell's buffering, it simply fills a stream with characters.

Line buffering is the default in C, but that buffer is different than the command shell's buffer in that it's used for performance reasons, not behavior reasons. You can switch I/O in C to be non-buffered and still be limited by the canonical mode of your shell.

What you mean with canonical mode is how the operating system handles I/O, which isn't covered by standard C, so system-dependent API calls need to be made to change the behavior of the I/O interface used by the standard C functions. This is made most obvious by the fact that your hello world program still uses the standard getchar function. You're not changing how standard C works, you're simply using non-standard functions to change how the system functions that standard C uses work.

>Oh yes …

Rashakil Fol commented: You evil wench! +6