Narue 5,707 Bad Cop Team Colleague

>It keeps changing my code.
Can you be more specific?

Narue 5,707 Bad Cop Team Colleague

>What is the situation at your location?
We adhere closely to standards and enforce correct behavior.

>Does this lack of control really hurt?
It can, very easily. One of the most important guidelines in programming style is consistency. That includes project-wide consistency even when multiple people are working on different modules.

Narue 5,707 Bad Cop Team Colleague

>usingnamespace
I'm reasonably sure you need a space between those two keywords. :)

Actually, you have tons of similar syntax errors. This compiles:

#using<System.dll>

using namespace System;
using namespace System::Diagnostics;

ref class B {
public:
  virtual void F(){
    Console::WriteLine("B::F");
  }
};
ref class D : B {
public:
  virtual void F() override {
    Console::WriteLine("D::F");
  }
};
int main(){
  B^ b = gcnew D;
  b->F();
}
Narue 5,707 Bad Cop Team Colleague

The SET clause can be a comma separated list of assignment expressions:

string command =
  @"update  Appointments " +
   "set     [startDate] = @Start" +
   "        , [endDate] = @End" +
   "        , [title] = @Title " +
   "where  ([appointment_id] = @Record)";
Narue 5,707 Bad Cop Team Colleague

>Crap, that's what I get for believing someone on another forum rather than using an official source.
That post was correct. You can portably depend on EXIT_SUCCESS meaning success, but you can't portably depend on the actual value being 0. Fun stuff, huh? ;)

Narue 5,707 Bad Cop Team Colleague

That's usually done by linking multiple object files together.

Narue 5,707 Bad Cop Team Colleague

>So would I add a variable in each function that states temp=temperatures.in?
You already have the variable. It's the parameter. Let's look at your first program with a function:

#include <stdio.h>
#include <ctype.h>

void my_function( char param[] )
{
  int i, first = 1;

  for ( i = 0; param[i] != '\0'; ++i )
  {
    if ( first )
    {
      param[i] = toupper( param[i] );
      first = 0;
    }
    if ( isspace( param[i] ) )
    {
      first = 1;
    }
  }
}
 
int main()
{
  char text[255];

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

  my_function( text );
   
  puts( text );
   
  return 0;
}

The effect of calling my_function is like this:

#include <stdio.h>
#include <ctype.h>

int main()
{
  char text[255];

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

  {
    /* Copy the value of the argument (text) to the parameter (param) */
    char *param = text;

    /* The body of the function starts here */
    int i, first = 1;

    for ( i = 0; param[i] != '\0'; ++i )
    {
      if ( first )
      {
        param[i] = toupper( param[i] );
        first = 0;
      }
      if ( isspace( param[i] ) )
      {
        first = 1;
      }
    }
  }

  puts( text );

  return 0;
}

A function is logically nothing more than a blueprint for a block of code. The parameters are placeholders for the actual arguments that you pass when you call it.

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

Remember how the parameters and arguments don't have to have the same name? This is a case where they literally cannot. So you pass temperatures.in and the parameter would be named something else, like temp, and have a type that matches what you pass.

Also, since your function returns a value, or at least, that makes the most sense in this case, the return type would match the type you're assigning to and you use the return statement inside the function:

float FahrenheitToCelsius( float temp )
{
  return (temp - 32.0) * 5.0 / 9.0;
}

Then you would call it like this:

temperatures[i].out = FahrenheitToCelsius( temperatures[i].in );

It's all very consistent, but it takes some time to see the patterns. Don't let frustration get the best of you. :)

Narue 5,707 Bad Cop Team Colleague

>I think that you shouldn't be that mean.
There was nothing mean about his post. It was politely worded as far as I can tell. The problem is that when you create a new thread for the same problem as your other thread, we basically lose all of the work that was done in the previous thread. This wastes your time as we have to start the troubleshooting process all over again to get a feel for your problem.

Narue 5,707 Bad Cop Team Colleague

>should be fun.
It always is. :) The only difference with this one is now you have a return value and you'll need to change temperatures[i].in to whatever parameter name you choose. In the last one we could still use text because that's what the parameter was called. The name of the parameter and the name of the argument don't have to be the same. By the way, this is a parameter:

void title_case ( char text[255] )

And this is an argument:

title_case( text );

Some people get confused about which is which, but a parameter is the variable that the function uses and an argument is the value of the variable that you pass to the function.

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

Try using the random numbers as indices into an array of words.

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

>Does anyone know why Unix developers seem to have an obsession with the words foo and bar?
http://catb.org/jargon/html/M/metasyntactic-variable.html

Narue 5,707 Bad Cop Team Colleague

>is C++ what i should start learning?
Probably not. I assumed you wanted to learn C++ from your posts. Python might actually be a better introduction to programming (it's more forgiving), but eventually you will want to learn C++.

Narue 5,707 Bad Cop Team Colleague

>for the most part recursion is retarded...
Recursion is great, when it's a good solution. Most people use recursion for retarded things. The Fibonacci and Factorial examples in books can attest to that.

>How can one expect to learn from a book when the book doesn't even give you any sort of examples?
You can't. Get a better book. Tell me which one you have right now and I'll recommend something better.

>what would I put in main.cpp
With the same function, you would probably want to create another member function for the public interface and leave add_end private:

class list {
  node *head;
public:
  //...
  void add ( int data ) { head = add_end ( head, data ); }
private:
  node *add_end ( node *list, int data );
  //...
};

Then you can just call add from main:

N.add ( newItem );
Narue 5,707 Bad Cop Team Colleague

>With Visual C++.. all my code is tested and always works before i post it.
I was quoting WaltP. He claimed that it didn't work, yet I didn't see any problems and on multiple compilers it works as expected.

>These people are simply boycotting me for their own reasons.
"These people"? Have you been getting this in other threads as well? In this thread only one person claims that your code is broken.

Narue 5,707 Bad Cop Team Colleague

>Because... of the Ewoks?
Because I don't need to explain why...or because I can't put it into words. :) But no, not because of the Ewoks.

Narue 5,707 Bad Cop Team Colleague

>Which is your favorite Star Wars and why?
Return of the Jedi. Because. :)

Narue 5,707 Bad Cop Team Colleague

>* What is your favorite genre(s)?
Science fiction/fantasy, technical, manga, history, and the occasional mystery.

>* Who is your favorite author(s)?
J.R.R. Tolkien, Orson Scott Card, Anne McCaffrey, C.S. Lewis, and Tom Clancy.

>* How much do you read per week?
20ish on average, more if I have a book that I'm really into. I spend approximately three hours reading every night before bed, but sometimes I'll sit down and read just for the heck of it.

>* What are you reading now?
I'm reading Star Wars: Bloodlines, one of the new Legacy of the Force books.

Narue 5,707 Bad Cop Team Colleague

>This is a really newb quest but how exactly do threads work.
It's not a newb question at all, so no worries. A thread is a thread of execution, which is a fancy way of saying that CPU time is divided between the running threads and each one is worked on in chunks. The net effect is that it appears as if multiple threads are executing simultaneously.

The nice thing about C# and .NET in general is that threads are dead easy to work with. Here is a tutorial introduction, and also a whole website that you should bookmark when working with .NET. :)

Narue 5,707 Bad Cop Team Colleague

>and you were like one of the main posters on that 'Virus Programming' thread!
Then it was the thread I was thinking of. That was a fun one. I actually remembered it being fun despite my awful memory. ;)

>Do you have any suggestions for a book to buy?
You can get a free ebook on C++ from MindView. I honestly haven't read the first volume (but it's highly recommended) and I enjoyed reading the second volume very much. However, I always recommend learning C++ from Accelerated C++ because it's short and sweet, and teaches C++ as it should be taught.

Narue 5,707 Bad Cop Team Colleague

>whether me being from a management background is it advisable?
Lessons learned from management will be very beneficial as a software developer. Actually, that can easily be a selling point for you because a lot of developers looking for jobs are a little weak on the social skills that you should be comfortable with.

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 am trying to make the program to ask user if he or she wants to continue
>when they click anywhere on the program.
That's extremely unconventional behavior. If I may offer a recommendation, how about using a progress bar and a cancel button? Naturally the encryption should be done in a separate thread so that the GUI is still usable. Not only is that easier that what you're asking, it's also what users will expect to see.

Narue 5,707 Bad Cop Team Colleague

>what help is this forum if nobody can help
It's not that nobody can help, it's that nobody chooses to help when you haven't shown us what you've tried. You simply asked for code or a link to code, which is frowned upon in this forum.

>ive already tried starting it
So post your code and we'll help you fix the problems.

>i just need a working version to see what i was doing wrong.
Too many people try to trick us into doing their homework for them. I don't believe you're doing that, but if I make an exception for you then it'll set a bad example. I'm truly sorry, but you need to show us what you've already tried before we can help in any meaningful way.

Narue 5,707 Bad Cop Team Colleague

>Well, they were wrong.
It depends on what they were referring to, but I'm going to assume they were correct if it was comp.lang.c. Wrong information doesn't last long on that group.

>Name one.
I can name three:

1) Take the sizeof a dynamically allocated array.
2) Take the address of a dynamically allocated array.
3) Initialize a dynamically allocated array to a string literal.

Those are the three cases where an array is used in object context instead of value context, and because a dynamically allocated array is not an array, the effect is different.

Narue 5,707 Bad Cop Team Colleague

>and it HAS to use a recursive function to insert the new node into the list
Just so you know, recursion is a piss poor way to work with linked lists. As for the algorithm, it would go something like this:

node *add_end ( node *list, int data )
{
  if ( list != NULL ) 
    list->next = add_end ( list->next, data );
  else {
    list = new node;
    list->data = data;
    list->next = NULL;
  }

  return list;
}

Since this is a homework assignment, I'll leave it up to you to figure out how it works. I can't do everything for you, ne? ;)

Narue 5,707 Bad Cop Team Colleague

>can anybody gimme an algo for reversing the words in a string in O(n) time....
Recursively copy the words to a new string. ;)

Narue 5,707 Bad Cop Team Colleague

>I've heard C is pretty popular to program in.
For the enlightened, yes. :)

>I want to make a simple window, with a search bar. By putting in either
>Hiragana, Romanji or English, it brings a pop-up with all 3.
You can certainly work toward that goal, but it's best to start smaller. At the very least you need to know a GUI library to write the window, a database library to link with the database of matching words, and enough C to pull it all together. It's not a project I would call difficult, but it's not trivial for a beginner either.

>I was hoping there may be a template, or tutorial or something of a simple
> window and search box, so I could copy the code and just make the strings?
If you don't want to write any code or learn how to do this, I'm sure you can toss somebody $10 on rentacoder.com. Sadly, there aren't templates for the majority of projects, so you'll have to learn enough to write the code. Also, if there were a template, you would still need to know enough to use it correctly. Cut and paste is a notoriously bad way to program. ;)

>Also can you download C for free?
C is free (as in beer), but you need a compiler. Fortunately, compilers are available for download for free (as in freedom). ;)

Narue 5,707 Bad Cop Team Colleague

I'll answer your question with a question. When you add a new digit onto the front of the list, why doesn't it become the new head? My usual recommendation when working with list logic is to get a handful of change and play with it on your desk. Then match the code to the shuffles you do with the change.

Narue 5,707 Bad Cop Team Colleague

>Before doing someone's homework for them at least test your code.
It looks like it should work just fine. How did you test it?

Narue 5,707 Bad Cop Team Colleague

>Yes, but there are some widely accepted ways to do certain things, like
>using all caps for constants. I was thinking what would that be here.
From what I've seen, the widely accepted way of doing it is to omit this-> .

>but it would help anyone taking a glance.
If you're reading for comprehension (the only case where your situation makes sense), you're doing more than glancing.

>Even in a moderately large class you might have to go back and forth to make see the function definition.
These days it's trivial to find the function definition without scrolling text. IDEs and text editors for programming will generally support this feature.

Narue 5,707 Bad Cop Team Colleague

That's twice this thread has been bumped unnecessarily. :rolleyes:

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

>I honestly can't remember what works in turbo c.
int main has always worked. :rolleyes:

Narue 5,707 Bad Cop Team Colleague

>How long should we expect to wait when retrieving a record from the middle of the file?
[TEX]50000 / 2 * 5 = 125000[/TEX] milliseconds without any details on what the difference is between 'interrogating' and 'retrieving', and assuming by 'middle' you really do mean the middle.

Narue 5,707 Bad Cop Team Colleague

>head = newPtr;
>if (head!=NULL)
> head->prev = newPtr;
The order for that is wrong. Look at it this way. This is what you want before setting head to newPtr:

0<-newPtr<->head<->...

But because you set head to newPtr before fixing head->prev, you get this:

0<-newPtr->head<->...

Notice the missing back link between newPtr and head. So the code should update the current head first, then set the new head:

if ( head != NULL )
  head->prev = newPtr;
head = newPtr;

>temp = temp->next;
>temp2 = temp2->prev;
You don't need the second statement. What you want is for temp2 to point to the node prior to temp. So along the line you know the current node and the last node that was looked at:

t   c
   |   |
~<-0<->1<->2<->3->~

       t   c
       |   |
~<-0<->1<->2<->3->~

           t   c
           |   |
~<-0<->1<->2<->3->~

               t  c
               |  |
~<-0<->1<->2<->3->~

The last one is important, and why the temporary pointer was used in the first place. When the current node is null, it has no link to the previous node, so you have to either save the previous node, or avoid getting to the null node in the first place. To save the previous node, you follow this logic:

c = head;

while ( c != NULL ) {
  /* Print c->Value */
  t = c; /* Save the current node */
  c = c->next; /* Go to the next node, now c is current and t …
Narue 5,707 Bad Cop Team Colleague

>void main()
I'll just get this out of the way. void main is incorrect. The correct definition of main is int main() .

>The syntax for templates is
>template < class T >
>and not
>template < typename T >
Both are correct. As a template parameter, class and typename have the same meaning. Your suggested change would do nothing.

>Any ideas?
You can't separate the template declaration and defintions. The export keyword was added to the standard for this, but it's extremely difficult to implement (not to mention the semantics are very tricky) and not many compilers support it in any useful fashion.

>undefined reference to `Queue::push(int const &)'
How are you building this? What compiler and OS are you using?

Narue 5,707 Bad Cop Team Colleague

>The only time I use this-> is to resolve ambiguous names.
Same here, and I only have ambiguous names when I'm maintaining code I didn't have control over in writing or when I'm stuck in a corner and can't use unique names. In other words, not often at all. ;)

Narue 5,707 Bad Cop Team Colleague

>file.write((char*)&obj, sizeof(obj));
>file.read((char*)&obj, sizeof(obj);
This is broken. What you're trying to do is convert an object into a sequence of bytes, an operation called punning. However, the rules for punning an object are very strict, and your class doesn't meet the requirements. When you try to pun a non-POD object into an array of char, you're risking all kinds of problems related to undefined behavior.

>void main()
I'll let conio.h slide, iamthwee, but not void main. I don't care if you were thinking of an ancient compiler when you wrote those programs, void main has never been correct C, even as far back as C's predecessor languages.

>That compiler is buggy, very old, not very compiliant with c or c++ standards, and has sever million other problems.
Actually, it's a pretty good compiler for C. The real problems show up when you try to write standard C++.

Narue 5,707 Bad Cop Team Colleague

>What is the coding standard here?
Different people/standards do different things. It's a stylistic issue.

>And what could be wrong with the first version?
Well, it adds unnecessary clutter that distracts from the meat of the code. I would also ask why that information is important enough to add this-> all over the place.

Narue 5,707 Bad Cop Team Colleague

>As a rule of thumb can I say that the prototype and the definition args
>must match, but the call can and will differ depending on how the arg is used in main?
Yes. In fact, that's exactly the rule of thumb that saves people from having to worry about how to pass multi-dimensional arrays. :)

>IF the code was set up for a pointer to a pointer, then *Array would be correct in the call?
*Array gives you the first string, "Toronto" in this case. It would be a pointer to const char, so no. This is a tricky area because the code is already set up for a pointer to a pointer. When you pass an array to a function, the first dimension is converted to a pointer. So these two declarations are identical:

void foo ( int array[] );
void bar ( int *array );

The declaration for BubbleSort could be changed the same way:

void BubbleSort ( const char **array, int size );

So Array is still correct when working with pointers to pointers in this case.

Narue 5,707 Bad Cop Team Colleague

>BubbleSort( &Array[ArraySize] , ArraySize);
If the variable is declared the same as the parameter, you need only pass the variable name. The only time you need to play around with addresses or indirection in a function call is when you have a complex type and need a subset of that type. For example, if Array were an array of arrays of strings (let's say a list of countries where each country has a list of ten cities):

const char *Array[][10];

Then you wouldn't be able to call the function using just the name, you would need to index one of the countries first:

BubbleSort ( Array[x], n_cities );

However, since the parameter and the variable declarations match:

void BubbleSort(  const char *array[] , int size );
const char * Array[] = { "Toronto", "Montreal",...

All you need is the name:

BubbleSort ( Array, ArraySize );

Ne? :)

Narue 5,707 Bad Cop Team Colleague

>How would I start from the back and move to the front?
You have two choices, really. You can use recursion to fake it, or add another link to each node that points to the previous node. Since you build your list in reverse anyway, you can just walk it forward and the sum can just fall out of that. But then you have the issue of printing, which is the same problem. :) However, a double linked list can be tricky because you have to manage twice the pointers:

#include <iostream>

namespace JSW {
  struct node {
    int data_;
    node *prev_;
    node *next_;
  };

  node *add_front ( node *list, int data )
  {
    node *nn = new node;

    nn->data_ = data;

    // nn is the new head
    nn->prev_ = 0;
    nn->next_ = list;

    // Be sure to set the back link
    if ( list != 0 )
      list->prev_ = nn;
    
    return nn;
  }
}

int main()
{
  using namespace std;

  JSW::node *list = 0;
  JSW::node *last;

  // Build the list in reverse
  for ( int i = 0; i < 10; i++ )
    list = JSW::add_front ( list, i );

  cout<<"Forward traversal:\n";

  while ( list != 0 ) {
    cout<< list->data_;

    // Only print a link if one exists :-)
    if ( list->next_ != 0 )
      cout<<"->";

    // Save the last valid node since 'list' will become null
    last = list;
    list = list->next_;
  }

  cout<<"\nBackward traversal:\n";

  // Do the same thing in reverse using 'last'
  while …
Narue 5,707 Bad Cop Team Colleague

>I need to know where to get a copy of bios.h(and any files that are used with it.)
They'll likely be worthless to you unless they came with your compiler to begin with.

>and the opengl header files.
Those headers come with the OpenGL library. All you need to do is get a copy of that, install it, and you'll have the headers.

Narue 5,707 Bad Cop Team Colleague

>head = new digit;
Why are you creating a new list? It strikes me that you want to use the existing nodes and just copy the data. I can also see other cases where the list being copied is shorter or longer than the destination list. As it is, you'll have intermittent memory issues because it looks like you're walking all over memory you don't own.

Narue 5,707 Bad Cop Team Colleague

>Do you really need a queue?
Well, the tags are being stored anyway, and since there's going to be a balance checking step, it makes sense to store them in the order that they were found. Thus, a queue. :)

>It sounds logical, I just can't figure out how to code it properly, like how to apply the "<" in the condition.
If you keep to that algorithm then you may discover the problems that I mentioned. However, since this is a homework project, it's unlikely that you need to write something bulletproof. The algorithm would go something like this:

while ( ( ch = fgetc ( in ) ) != EOF ) {
  /* Pull a tag */
  if ( ch == '<' ) {
    char tag[MAX];
    int i = 0;

    tag[i++] = ch; /* Save the current < */

    /* Go until the end of the array, the end of the file, or > */
    while ( i < MAX && ( ch = fgetc ( in ) ) != EOF && ch != '>' )
      tag[i++] = ch;

    /* Add the tag to the queue */
    enqueue ( tag );
  }
}
Narue 5,707 Bad Cop Team Colleague

>Each node is like "00343068", etc. when it's suppose to be like 123
Those are addresses. You're printing the value of the node itself rather than the Value member:

cout << temp->Value << endl;