Narue 5,707 Bad Cop Team Colleague

>Always Remember The GOLDEN RULE that
That's the golden rule? Gold must be pretty worthless these days if all of the vastly superior rules were shoved aside for that one.

>when any funtion needs to return any value or recieves a value then it
>should proceed with a type of value it can recieve usually an int
Um, return and receive tend to be mutually exclusive. You should pick one when talking about return types. I'd recommend "return". "receive" is generally what one means by parameter or argument.

>ending with semicolon (;)
I think it's a a fair assumption that we all know what a semicolon is.

And of course, you didn't answer the question of why int main is preferred over void main. You just made the common mistake of pretending that main is a normal function and propagated the misconception that main's return type is the decision of the programmer. Both of which are false.

Aia commented: Gold is not what is used to be. +2
Narue 5,707 Bad Cop Team Colleague

>I'm not quite sure the difference between strcmp and == operator when comparing 2 different strings
Presumably you're using C-style strings, otherwise strcmp wouldn't be an option. So with that in mind, you should use strcmp because it compares the contents of the strings while == compares the address of the first elements in the strings. Given the following comparison:

char a[] = "test";
char b[] = "booga";

if ( a == b ) {
  // Stuff
}

This comparison is functionally equivalent:

char a[] = "test";
char b[] = "booga";

if ( &a[0] == &b[0] ) {
  // Stuff
}

That's a huge difference from the intended operation of comparing each character in the two strings for equality. In that case, you use strcmp.

WolfPack commented: Good Explaination +8
Narue 5,707 Bad Cop Team Colleague

This is a special operation that can't easily be done using just the basic queue operations. So you should make it a non-member friend function and sort the internal storage structure.

Rashakil Fol commented: Way to totally ignore the requirements of the homework assignment +6
Narue 5,707 Bad Cop Team Colleague

>So, if a one day boycott will do no good, then tell me what to do.
Put simply, a boycott won't work. To be successful it would have to be widespread and long term, two things which are unlikely to happen. If you have a car and need to use your car, you have to get gas. It's as simple as that. The only solution is alternative transportation. Minimize your use of fuel as much as possible, or remove it entirely by purchasing a vehicle that uses something other than fossil fuels.

christina>you commented: This is for the bad rep I gave you and for me being a dumbie. +9
Narue 5,707 Bad Cop Team Colleague

Hmm, if you've already made up your mind about leaving (which it seems you have), why are you still here? I don't hate you*, but you clearly have a problem with criticism. Since forums like this tend to be more critical than real life due to anonymity, you need to grow some thicker skin. You also need to understand that people have different personalities and ways of expressing themselves. Normal for me is clearly very offensive to you, but I'm not going to change just because you don't like it. I doubt anyone will.

So if you're going to leave, leave. Stop whining about how poor little you is being hated by the mean people. If you just suck it up and stop making such a stink, you'll realize that things blow over very quickly and disappear. If you keep complaining about imagined insults, you just put yourself into a downward spiral that ends up as a self-fulfilling prophecy.

If you really do think you're being harassed, report those people to the admins. A legitimate grievance is worthless if the people who can take care of it don't know that it exists.


* Really, I don't. I don't even know you, but I have come to several conclusions about you that annoy me. However, I don't let those conclusions dictate how I interact with you, so that's completely irrelevant. I'm just as "mean" to other people as I am to you, so don't feel like …

sk8ndestroy14 commented: Thanks +1
Narue 5,707 Bad Cop Team Colleague

Here's a challenge for you C++ aces. The challenge is to write a function with the following declaration:

unsigned long extract_digits ( unsigned long x, size_t n, size_t i );

This challenge has three parts.

Part I (Beginner):

Write the extract_digits function. It should return a sub-value of the first parameter consisting of n digits starting at i. For example, the first 3 digits of 12345 starting at 1 should return 234.

Part II (Intermediate):

Make the extract_digits function as solid as possible given unexpected input.

Part III (Expert):

Make the extract_digits function as fast as possible.

There's no need to submit the solution when you're finished. This is a personal challenge, not a contest. However, programmers are a naturally competitive species, so if enough people post solutions to this thread, I'll judge them and maybe even give away a prize. :)

WolfPack commented: Nice. +7
Narue 5,707 Bad Cop Team Colleague

>This was sent to me today...
You fall for a lot of scams and hoaxes, don't you?

WolfPack commented: he he. good observation +7
christina>you commented: OMG. You're retarded. -2
Duki commented: he he. bad observation +0
arjunsasidharan commented: haha.. true true.. +2
John A commented: Oh brother, at least she isn't as bad as Quaetrix... +12
Narue 5,707 Bad Cop Team Colleague
Before You Ask
  • Read our Forum Rules.
  • Engage your brain! We understand that running into a problem can turn off the rational centers of the brain, but please sit back and think for a bit about your problem before running off to find help. All too often a little common sense is all you need.
  • Search the forum. If you're having a problem, chances are good that someone else has had the same problem. Please search the forum for existing answers before starting a new thread. Nothing is more irritating to a long time member than answering the same question for the umpteenth time because someone didn't use the forum's search feature.
  • Search the web. Even if the same question hasn't been asked on our forum, it may have been asked somewhere else on the web. Search engines are incredibly powerful, and they won't flame you about wasting their time if you ask a dumb question. We might. ;)
Composing A Good Question
  • Don't hijack an existing thread. If you searched the forum before asking and the help provided in an existing thread did not solve your problem, then your problem is different enough to justify creating a new thread.
  • Create a meaningful thread title. So you've searched and haven't found anything that fits your problem? Great! We can help, but you need to peak our interest with a thread title that briefly describes your problem. Many members browse the topic list and choose which threads to …
William Hemsworth commented: Its been helpful to have :) +3
tux4life commented: Nice and really helpful ! +1
FrozenSnake commented: Good thread! Important! +0
Bukhari1986 commented: Nice Rules. Appreciated. +0
Narue 5,707 Bad Cop Team Colleague

Before You Ask

  1. Engage your brain! We understand that running into a problem can turn off the rational centers of the brain, but please sit back and think for a bit about your problem before running off to find help. All too often a little common sense is all you need.
  2. Search the forum. If you're having a problem, chances are good that someone else has had the same problem. Please search the forum for existing answers before starting a new thread. Nothing is more irritating to a long time member than answering the same question for the umpteenth time because someone didn't use the forum's search feature.
  3. Search the web. Even if the same question hasn't been asked on our forum, it may have been asked somewhere else on the web. Search engines are incredibly powerful, and they won't flame you about wasting their time if you ask a dumb question. We might. ;)

Composing A Good Question

  1. Don't hijack an existing thread. If you searched the forum before asking and the help provided in an existing thread did not solve your problem, then your problem is different enough to justify creating a new thread.
  2. Create a meaningful thread title. So you've searched and haven't found anything that fits your problem? Great! We can help, but you need to peak our interest with a thread title that briefly describes your problem. Many members browse the topic list and choose which threads to post in only …
WolfPack commented: Nice +7
Aia commented: Very clear +1
Salem commented: Absolutely! +36
jephthah commented: i keep referring people here, i might as well give it another green +6
Anuradha Mandal commented: Thanks. +0
Narue 5,707 Bad Cop Team Colleague

If you want to talk about anything and everything, that's called chatting. Daniweb has a chat room that's incredibly boring 99% of the time. Why not take random ramblings there so we can get some more action?

arjunsasidharan commented: :D +1
Narue 5,707 Bad Cop Team Colleague

>There is some syntax of cin that allowes us to ignore the \ns.. Isn't it?
You're probably thinking of the ws manipulator, but it discards all whitespace. If you want more control, you have to write your own manipulator:

class scan {
public:
  scan ( const char *init ): fmt ( init ) {}
  friend istream& operator>> ( istream& in, const scan& s )
  {
    while ( *s.fmt != '\0' && in && in.peek() == *s.fmt ) {
      in.get();
      ++s.fmt;
    }

    if ( *s.fmt != '\0' )
      in.setstate ( ios::failbit );

    return in;
  }
private:
  mutable const char *fmt;
};

And of course you can write custom manipulators so that they're used in exactly the same way as standard manipulators. This is only slightly more awkward than what the OP had before:

cin>> first >> scan ( "\n" ) >> middle >> scan ( "\n" ) >> last;

Of course, that's effectively a no-op because most formatted input discards leading whitespace by default. That's why removing those strings altogether still works as expected.

thekashyap commented: Thanks for the insights, though i'm not a big fan or cin/cout it's good to learn more :) +1
Narue 5,707 Bad Cop Team Colleague

>Theres absolutley nothing wrong with using the fstream library for
>handling Input/Output streaming.
No, there's not. However, when you say to use fstream.h instead of fstream, you're not using the fstream library. You're using some non-standard library with inconsistent semantics that happens to be called fstream.

iamthwee commented: yes and since he himself pointed out the OP wanted to use c++ there is no excuse for the confusion. +9
Narue 5,707 Bad Cop Team Colleague

>- use inline functions (new compilers do this implicitly though)
The compiler is in a better position to know what functions are best inlined. An explicit inline keyword strikes me as akin to the register keyword in premature optimization.

>- use registers.
Speaking of the register keyword, don't waste your time. A lot of compilers just ignore it, and those that don't tend to produce less efficient code because the programmer doesn't really know how to dole out register time.

>-- using the right type of variable, meaning, if yyou need to use decimal
>values in your program, if they're not too big, consider using float rather
>than double...
For size optimization, yes. For speed optimization, double is likely to be as fast or faster than float because many FPUs will work internally in double or long double precision. Matching the internal type can be faster by avoiding conversions.

>-- (where you can) using pointers instead of arrays, since it uses less memory
You're talking about a minimal constant size difference, if it exists at all. I wouldn't call this an optimization.

>-- cleaning useless information off the buffer
I don't really see how this matters.

>I`ve seen this data caching in a number of places... wat exactly does that refer to..
Caching is saving the result of an expensive operation so that you can quickly refer to it at a later time without repeating the expensive …

Narue 5,707 Bad Cop Team Colleague

>Is it correct?
If I say yes, will you believe me and stop trying to repeat your explanation over and over?

Salem commented: It's a marathon isn't it. +6
Narue 5,707 Bad Cop Team Colleague

Either you're incredibly dense, or you're putting way too much thought into something simple. Given char *str = "Hello"; , "Hello" is const, str is not. The assignment is allowed, but you can't use str to modify "Hello". That's as deep as it goes, so stop digging.

John A commented: Wow, I wish I could explain stuff that simply. +11
Narue 5,707 Bad Cop Team Colleague

My resolution for the rounded corners dilemma was to go ahead and add an option into the USER CP that allows members to disable rounded corners, the navigation dropdown menu, or both.

While I appreciate all of the work you do, I need to put on my Narue hat to properly respond to this. Don't take it personally, I hold you in the highest respect.

This is a piss poor solution. Something doesn't work right, so you offer the option to disable it instead of actually finding and fixing the problem? :-/ Yea, I'd get laughed at if I tried that in any of my software. As a temporary fix and a nice option it's okie dokie, but as a permanent fix, I can honestly say that it sucks ass.

This message has been brought to you by Diet Rite Pure Zero with Splenda. No calories and it actually has flavor! We now return you to your regularly scheduled programming.

>And of course, you can also disable avatars in posts
Perish the thought. :-O

p.s. It is a great deal faster. Thanks! :)

WolfPack commented: ha ha ha. I like the Diet Right Advert. +7
Narue 5,707 Bad Cop Team Colleague

>infact, i have made my website about c programming..
I'd recommend learning C before trying to teach it. Your code is poorly written and your explanations of the code are severely lacking.

>Don't. Get the Express version of VS 2005:
If you stick to C, Visual Studio 6 is okay. If you use C++ aslo, definitely upgrade.

Narue 5,707 Bad Cop Team Colleague

>Here is the PROOF you need.....
I don't need proof that I'm right. I can't believe you actually thought that using gets in an extremely controlled environment would mean anything. By gets not being safe, here's my proof:

#include <stdio.h>

int main ( void )
{
  char pretest[20] = {0};
  char dummy[2];
  char posttest[20] = {0};

  int x;

  printf ( "Enter a number: " );
  fflush ( stdout );
  scanf ( "%d", &x );
  gets ( dummy );

  printf ( "pretest: \"%s\"\n", pretest );
  printf ( "posttest: \"%s\"\n", posttest );

  return 0;
}

Run that and type "123you're a moron". Overflowing a buffer is undefined, but with any luck you'll see something interesting.

Aia commented: Thanks for example. -Aia +1
Narue 5,707 Bad Cop Team Colleague

Oh come on! Even I have an infraction... Wait, you probably shouldn't be comparing these things to me. I'm a bad influence.

joshSCH commented: Can you see who reps you? +4
Narue 5,707 Bad Cop Team Colleague

That about covers it. Rep is a superfluous feature, but it is fun occasionally.

>Having said that...how do I access this report?
You can see your rep under the control panel.

jbennet commented: well said - jbennet +11
Narue 5,707 Bad Cop Team Colleague

>do you think that the people who hand the red dots out would be so bold to
>say stuff like that if they knew their names were being attached to
>everything they said?
If they don't have the rocks to tag their names now, I'm sure that automatically listing their names would weaken their comments greatly. ;) I respect people who can voice their opinion openly, and conversely I don't respect people who hide behind anonymity when they flame.

'Stein commented: Agreed. :icon_biggrin: -'Stein +6
Narue 5,707 Bad Cop Team Colleague

Where's the rant and rave smiley? :@ doesn't cut it for my level of bitchiness. Are you trying to tell me something? ;)

christina>you commented: cursing is not allowed. -1
Rashakil Fol commented: I don't see any cursing. +4
Narue 5,707 Bad Cop Team Colleague

>What I meant with the things not being allowed is that the output wanted was to be straightforward.
The output has no relationship to how you produce the answer. You can solve the problem a dozen wildly different ways and get exactly the same desired output that you posted.

>Only the sign matters here (+ve, -ve, zero).
>return (sp1->wordOccurrence - sp2->wordOccurrence) ;
Sure, only the sign matters, but it's also the sign that kills you with this code. You're a smart guy, so I'll give you three words of advice on why this is a poor solution: signed integer overflow.

~s.o.s~ commented: *shoots himself in the head* I overlooked that possibility, thanks - ~s.o.s~ +14
Narue 5,707 Bad Cop Team Colleague

Hmm, interesting that your problem is comparing strings. In this case you would use strcmp:

if ( strcmp ( buffer, "terminate" ) == 0 ) {
  // Notify the other program of termination
  return 0;
}
Salem commented: You'd think someone who managed IPC could have figured out strcmp() - Salem +6
Narue 5,707 Bad Cop Team Colleague

I hope that your code isn't supposed to be valid C, because it's not.

>But he wanted me to give a solution without using 2 - dimensional arrays.
Well, you can do it with a frequency table, which is essentially a one dimensional array:

char FirstNonRepeated ( const char *str )
{
  // unsigned char for space efficiency
  unsigned char saved[CHAR_MAX + 1] = {0};
  size_t i;

  // Build the frequency table
  for ( i = 0; str[i] != '\0'; i++ )
    ++saved[str[i]];

  // Return the first character with no repeats
  for ( i = 0; str[i] != '\0'; i++ ) {
    if ( saved[str[i]] < 2 )
      return str[i];
  }

  return '\0'; // No non-repeated chars
}

In C++ I would expect to see you use a map or hashmap, and if you used an array I would ask you to defend your decision. If you used a map or hashmap I would ask you to defend your decision too, so don't read into that. In an interview we try to get a good feel for how your brain works. ;)

You can also solve the problem in a less elegant manner using nested loops:

char FirstNonRepeated ( const char *str )
{
  size_t i;

  for ( i = 0; str[i] != '\0'; i++ ) {
    // Find any repeats
    int is_repeated = 0;
    size_t j;

    for ( j = 0; str[j] != '\0'; j++ ) {
      // Make sure the character skips itself …
Aia commented: I learned with this example +1
Narue 5,707 Bad Cop Team Colleague

>Do i need to declare another iterator to traverse the rows and another one to traverse each elements?
Yes. Each row is an independent data structure, so you have no choice but to use two iterators. It's exactly the same as when you build the vector of vectors:

#include <iostream>
#include <iomanip>
#include <vector>

int main()
{
  std::vector< std::vector<int> > v;

  for ( int i = 0; i < 10; i++ ) {
    v.push_back ( std::vector<int>() );

    for ( int j = 0; j < 10; j++ )
      v[i].push_back ( i + j );
  }

  std::vector< std::vector<int> >::iterator row_it = v.begin();
  std::vector< std::vector<int> >::iterator row_end = v.end();

  for ( ; row_it != row_end; ++row_it ) {
    std::vector<int>::iterator col_it = row_it->begin();
    std::vector<int>::iterator col_end = row_it->end();

    for ( ; col_it != col_end; ++col_it )
      std::cout<< std::setw ( 3 ) << *col_it;
    std::cout<<'\n';
  }
}
John A commented: Glad to see you're posting on DaniWeb again! - joeprogrammer +6
Narue 5,707 Bad Cop Team Colleague

>There's only one private function in B. What made the size to be 4?
Member functions don't generally apply toward the size of an object. If they do, I would question the quality of your compiler. The thing that made the size be 4 is the internal object stuff that C++ does behind your back, in this case, probably the pointer for a virtual table..

SpS commented: Nice ~~SunnyPalSingh +3
Narue 5,707 Bad Cop Team Colleague

>I downloaded the microsoft visual studio and it confused the hell outa me.
Anything will at first. Either you have to deal with the complexity of an IDE (that's a compiler, debugger, editor, etc.. all rolled up into one graphical application), or the complexity of learning command line tools. You should learn both, but starting with an IDE will probably be easier. Since you already have Visual Studio, I can walk you through setting up a project and testing it.

Step 1) Go to File->New->Project
Step 2) From the project templates list, choose Empty Project[1]
Step 3) Type in whatever name you want for the project and hit OK
Step 4) Look for the Solution Explorer[2] and right click on the Source Files folder
Step 5) Choose Add->New Item
Step 6) From the templates list, choose C++ File (.cpp) and call it something like main, then click Add. Now the text editor has a text file in it called main.cpp.
Step 7) Paste this code into the editor:

#include <iostream>

int main()
{
  using namespace std;

  cout<<"Hello, world!\n";
}

Step 8) Type ctrl+F7 to compile the code
Step 9) Type ctrl+F5 to run it

After the project is set up, the work is minimal. If you want, you can just reuse the same project until you're more comfortable with the IDE. :)

>what is a compiler?
Simple answer: A compiler turns your source code into a working …

Narue 5,707 Bad Cop Team Colleague

Printing in .NET is funky, but simple. Once you get the hang of it it's no problem, but that first hurdle is figuring out how the heck the parts all fit together. Printing multiple pages is handled inside the PrintPage event handler. The handler selects which page to print and also notifies the print controller whether more pages exist with e.HasMorePages. Let's say you get your info from records in a data table. You could use a Page variable as an index into the data table, and when it reaches MaxPages, you set e.HasMorePages to false. My VB is kind of weak right now, so here's some C#:

private int _page;
private int _maxPage;
private PrintPreviewDialog _preview = new PrintPreviewDialog();
private PrintDocument _document = new PrintDocument();

public MyClass()
{
  //...
  _document.PrintPage += PrintPage_Handler;
}

public void PrintAll()
{
  _page = 0;
  _maxPage = _dtMaster.Rows.Count;
  _preview.Document = _document;
  _preview.ShowDialog();
}

private void PrintPageHandler( object sender, PrintPageEventArgs e )
{
  // Get info to print (name, address)
  string name = (string)_dtMaster[_page]["Name"];
  string addr = (string)_dtMaster[_page]["Address"];

  // Draw the strings
  //...

  e.HasMorePages = ++_page < _maxPage;
}

Using the preview dialog instead of the print dialog will save you paper while testing. ;)

Narue 5,707 Bad Cop Team Colleague

>the only way to be sure that your code is completely portable is to return 0 when the program exits.
EXIT_SUCCESS is completely portable. The language standard defines it as such, along with EXIT_FAILURE and 0.

Narue 5,707 Bad Cop Team Colleague

>I am not so good at the whole function thing so
Functions are very simple. You can think of them as a named block of code. Let's walk through a few steps of factoring your code into a function. First, take the code you want in a separate function and wrap a block around it:

#include <stdio.h>
#include <ctype.h>
 
int main()
{
  char text[255];
  int i, first = 1;

  printf( "Enter String: " );
  fgets( text, 255, stdin );

  /* This is the blueprint for your function's body */
  {
    for ( i = 0; text[i] != '\0'; ++i )
    {
      if ( first )
      {
        text[i] = toupper(text[i]);
        first = 0;
      }
      if ( isspace( text[i] ) )
      {
        first = 1;
      }
    }
  }
   
  puts( text );
   
  return 0;
}

You need to take note of two things: First, does the block rely on variables created outside of it? Second, does the block just have a side effect or does it actually produce a result? The answer to the first question is yes, the block uses the text array. It also uses i and first. The answer to the second is a little harder. Since the only changes are the ones made to the text array, you can safely say that the block only has a side effect, so we'll go with that to make things easier. :)

Those two questions determine the parameters, local variables, and return type of your function. Since you use …

Salem commented: Nicely done - Salem +4
Bench commented: A very patiently explained answer +1
Narue 5,707 Bad Cop Team Colleague

There are essentially two ways to extend a language. The first way is through libraries and other modules that don't break the rules of the language but still add functionality. An example of this is the Python/C API that let's you use Python from a C or C++ program.

The second way to extend a language is through a preprocessor. This is when your extensions literally aren't available to the language in question. An example of this would be adding a foreach construct to C++:

vector<int> v;

//...

foreach ( int x in v )
  cout<< x <<'\n';

This involves writing a program that first translates the new construct into valid C++ before passing it on to a C++ compiler.

mattyd commented: Very Helpful in Answering Post. +1
Narue 5,707 Bad Cop Team Colleague

>i just read a thread here that had some interresting talk and people...it was called 'Virus Programming'
I'm sure it was interesting if it's the thread I'm thinking about. ;)

>Do i have to be in uni to learn a programming language
Most certainly not! Anyone with a computer and basic skills using it can learn how to program.

>just wanted to know if learning langauges and how to write it was possible
>to do with no tuition or help from others.
No tuition, yes. No help, that's harder. I learned with very little help, and it's a long, difficult, frustrating path. Fortunately, help can be found for free on forums such as these.

>could i just read forums and find good links?
Yes, though it's highly recommended that you get a good book as well.

>should i just not bother till i learn more at school or something
No! If you're interested in programming, the sooner you start learning the better. Programming is very hard, but it's also very accessible. Most of the best programmers are almost completely self-taught.

Narue 5,707 Bad Cop Team Colleague

I don't know of any, but keep in mind that the game you're looking for will either be gimped due to lack of funding or overloaded with ads and other ways of generating revenue beyond a subscription.

p.s. WoW sucks, Everquest 2 is where the cool people play. ;)

Narue 5,707 Bad Cop Team Colleague

Okay, it looks like you're confusing C, C++ and Java.

>#include <string.h>
This supports string handling on array based strings, not the string class. For that you want to include <string>. I know it's confusing, but sadly, that's how it is. :(

>boolean Ispalindrome()
boolean isn't a keyword in C++. You probably want bool instead.

>string s1 = s.reverse;
The string class doesn't have a reverse member, which is fascinating since I'm pretty sure there's a kitchensink member. ;) There's a reverse function in the <algorithm> header, and you pass it a start and end iterator. This might work for you:

#include <algorithm>
#include <iostream>
#include <conio.h>
#include <string>

using namespace std;


class palindrome
{
  string s;

public:

  palindrome()
  {
    s="null";
  }

  palindrome (string s1)
  {
    s=s1;
  }

  bool Ispalindrome()
  {
    string s1 = s;
    
    reverse(s1.begin(), s1.end());

    if (s==s1)
      return true;
    else
      return false;
  }
};

int main()
{
  palindrome s1("How are you");
  cout<<s1.Ispalindrome();
  palindrome s2("BOB");
  cout<<s2.Ispalindrome();

  getch();
  return 0;
}

On a side note, conio.h is a non-standard header, so your code isn't portable. You only include it for getch, and you can replace getch with cin.get to a similar effect without sacrificing portability.

Narue 5,707 Bad Cop Team Colleague

>cin and cout are none of those.
>They are objects.
cin and cout are identifiers referencing objects.

Narue 5,707 Bad Cop Team Colleague

C Unleashed by Richard Heathfield and friends should cover most of what you need.

Narue 5,707 Bad Cop Team Colleague

>can anyone tell me if what i have is correct or almost correct
Not to hurt your feelings, but it's not even remotely close. This is a case where I'll recommend that you sit down with your teacher and get some face to face help. It would save us both some time. :)

John A commented: Well said. --joeprogrammer +3
Narue 5,707 Bad Cop Team Colleague

>'d like to know how I can use either string or char to get the user to input 15 or less characters
You can't portably do this. It requires a finer control of the input device than standard C++ supports. However, if you simply want to read lines and truncate the string to 15 characters if you read more than that, it's trivial to do:

#include <iostream>
#include <string>

using namespace std;

int main()
{
  const int max = 5;

  string s;

  // Read lines until the user gets tired
  while ( getline ( cin, s ) ) {
    // Trim the size to 15 if we read too many
    if ( s.size() > max )
      s.resize ( max );

    // Make sure it worked
    cout<< s <<'\n';
  }
}
Narue 5,707 Bad Cop Team Colleague

>1) Do big-oh and theta both represent the worstcase for the running time?
They represent whatever case you're analyzing.

>2) How do I know when to use theta?
Theta is when you can achieve it. It's a much stronger claim than Big O because it's a tighter bound.

Narue 5,707 Bad Cop Team Colleague

>What would you do in such a case?
It depends on how far you want to go. If you simply don't want to be associated with the project, you can turn it down at the risk of losing your job. If you feel the project should be cancelled, you can fight a lot of battles to get it cancelled (very likely losing your job and/or going through a lot of unpleasant experiences in the process), keeping in mind the slim chance of success.

Perhaps a better route would be to accept your assignment and attempt to improve the game. However, an ethical developer is aware that other opinions exist and is tolerant of them. These things are very much a matter of perspective, and if you're not careful, you could easily cross lines that shouldn't be crossed.

~s.o.s~ commented: Welcome back Miss Narue, hope you let bygones be bygones and stay a bit longer this time -- ~s.o.s~ +7
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

>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

>the compiler says the functions I am using are deprecated
My copy of the standard says no such thing. This is one case where it's okay to use a pragma to make the compiler shut the hell up.

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

I refuse to look at your code until you format it like a normal human being. It would also help if you'd stop acting like a wuss and ask a smart question.

Narue 5,707 Bad Cop Team Colleague

>but i have seen in many others threads people have asked to write
>codes even some people have asked to write there code give in there assignments
And in how many of those threads did those people get flamed for it? I'm willing to bet pretty much all of them.

>but he/she can also make me understand the logic behind the that algorithm...
Yes, but you asked for code. That suggests that you're making no attempt to understand the problem or solve it for yourself. A better way to post would be to ask for help understanding the problem, while specifying things you've already tried. At least that way we know you've tried to think for yourself.

Narue 5,707 Bad Cop Team Colleague

Presumably, mvwprintw is just a wrapper around some form of printf, so unless you want to look at your documentation, we can only assume that the format modifier follows the same rules.

The asterisk means that a value will be supplied as a later argument. The first asterisk is the field width and the second is the precision. I'd recommend testing how it works by hard coding values. For example:

printf ( "%5.2s\n", "abcdefghijklmnopqrstuvwxyz" );
Narue 5,707 Bad Cop Team Colleague

>who are you to decide this ??
The forum rules decided this and the community enforces it. If you have a problem with that, leave.