Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Can't you just put the common files in a library and include the library in each of the projects?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can't use strtok() on a const char* because strtok() will change the contents of the string. Copy the const char* into a buffer and use that for strtok()

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

String literals can not be changed because most compilers put them into read-only memory. How to change that? Notice that you have to make each buffer large enough to hold whatever it is that DIAG_ReadMem32() wants to copy into it. If you don't know exactly how big to make it, take a guess then double it.

char sCmdInt[8][255] = {0};
strcpy(sCmdInt[0],"123");
strcpy(sCmdInt[1],"234");
DIAG_ReadMem32(sCmdInt[0], sCmdInt[1]);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>cardslist(); //is this the right way to call cardslist?
Functions must be declared before they can be used. Read this link


>>card[0].name = "geezard"; //errors occur from this line onwards

You can't assign a string to a character array like that. Either make name a pointer or use strcpy() strcpy(card[0].name,"geezard");

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Today is ok but it was pretty slow a couple days or so ago. Sometimes its my ISP, not DaniWeb.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

how to invoke another process is operating system dependent. fork() creates another process from the currently running process, it does not invoke a new process that is not currently running -- and its only supported by *nix machines.. system() as suggested by dave is supported on all (or most) operating systems.

>>Also, gor interfacing a gui with my c++ code,should i go for vc++?
vc++ is NOT a language -- its just another IDE/compiler like g++.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I don't know exactly how you write a literal wchar_t that has a non-ASCII value

You need a keyboard that supports multi-byte languages, such as Chinese and Japanese.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>@AD did you edit by any chance?

Yes. My statement was incorrect. C99 allows const, previous versions did not. You have to be careful about what versions of c standards people are talking about. The new Cx00 (or whatever it will be called) allows a lot of other stuff that is new to the C language. such as this

int x = 100;
int array[x];
nbaztec commented: You could've said No & make me look stupid; but you didn't :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There should have been a * in that statement wchar_t *a = L"ab"; or like this wchar_t a[] = L"ab"; In any event you can't put two characters in single quotes and stuff them in a single byte of wchar_t.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think just by taking a look at definition of a nested function, its features become clear.

There is no such thing as nested functions in C language, so the features are not clear at all.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

C is about as close as one can get to assembly without actually writing assembly. Before C could support nested functions there would have to be support for them in assembly language. And I know that its not supported on Intel based computers, and probably not any other processors either.

If pascal supports nested functions then the pascal compiler must be actually making them separate functions like C language because the underlying assembly language stack frames doesn't support that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>He says: wchar_t or Wide Character stores 2 bytes instead of 1 so we can feed 2 chars

Again you probably misunderstood him. Yes, wchar_t is more than 1 byte (sometimes 2, sometimes 4 or more depending on the operating system). That doesn't mean it stores two or more characters in just one wchar_t. wchar_t someWCHAR = L"ab"; Like all strings it has to be surrounded with double quotes, not single.

The reason wchar_t is more than 1 byte per character is because an alphabetical character in some languages can not be represented in just one byte.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Well he dictated that for that matter,
That is a different story altogether. You mis-quoted him in your original statement. There is a difference between telling you he doesn't want your programs to do that then it is telling you the c standards say you can't do that. Its called "coding standards", which you will encounter throughout your programming career.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>it's nowhere written that C expects VOID MAIN!
compilers are (and do) allowed to support that.

>> mean if we can just use const in C, then why use #define, off the top of my head, is it due to this? :

Both C and C++ supprot macros and const. macros are used for other things which const can not.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Some of those questions may be true or false depending on the version of c and c++ standards. But current c/c++ standards are like this:

>>In C program , the MAIN() should NOT RETURN a value
That's a lie, and has always been false. Either you misunderstood him, or it has no clue what he is talking about.

>>He stated I'm wrong.
Stop taking that course because all he will do is tell you more lies and mis-information.

>>C does NOT have REFERENCE variables.
True -- C has pointers

>>C++ ,REFERENCE variables are USED in functions
Obviously true. Reference variables could be declared globally but not used there.

>>C does NOT SUPPORT DEFAULT arguments.
True

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There is no reason why this should not work, unless the function DIAG_ReadMem32 is attempting to change the contents of either of those pointers.

char *sCmdInt[8] = {0};
sCmdInt[0] = "123";
sCmdInt[1] = "234";
DIAG_ReadMem32(sCmdInt[0], sCmdInt[1]);

If the values in the array are hex numbers, such as "0x100", then you can use strtol() to convert them to integers

int x;
char str[] = "0x123";
char *ptr = 0;
x = strtol(str,&ptr, 16);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

And goto might get you a failing grade on your program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In Alphasort() you strcmp() is NOT case insensitive. You need to use a case-insensitive function, such as stricmp() or strcasecmp(), depending on the compiler you are using.

Or you could write your own compariso function by copying both strings into a temp variable, convert each to all UPPER case then use strcmp() in the temp strings.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The strings Heavy Normal and Low have to be in doubl quotes, not single quotes.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to modify function parameters to pass them by reference instead of by value so that the changes made by the function can be seen by the whoever called it. void readData(ifstream &fin, double &sidea, double &sideb, double &sidec) Now do something similar with the other functions.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

c++ was derived from C, and C never ha them either.

What would be the purpose of a nested function? What features could nested functions give you that normal functions do not?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 12: for (i=1; i<=N; i++)

Array elements always begin with 0, not with 1. So when that loop reaches N the value of i will be beyond the range of the arrays. The loop should be coded like this: for( i = 0; i < N; i++) >>the program will tell me like the over-roll grade .. and stuff
You need to be just a tad bit more technical and explict in your description. "and stuff" doesn't tell us anything.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> Form2^ form2 = gcnew form2;

Watch the capitalization. Should be Form2^ form2 = gcnew Form2; Move line 1 down below that #pragma once to let the compiler's preprocessor be more efficient.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

named semaphore is here for *nix. MS-Windows example.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

VariantClear() sets vt to VT_EMPTY, you don't have to do that yourself.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You stated you wanted to open another form when you pressed a button. Form2.h contains that form. Each form is in another class. Change Form2 to whatever you named the form you want to display when the button is clicked.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>can we use the continue statement in if-else statement?
No

>>i know the continue statement only can use under for loop right?
No. Can also be used on do and while loops.

pseudocode

set loop counter to 0
beginning of loop
   increment (or decrement) loop counter
   if loop counter matches some condition
      exit the loop
   do something here
end of loop
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sample basic code? This is about as basic as you can get

#include <stdio.h>

int main()
{
   printf("Hello World\n");
   return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 31 and 32 are asking for keyboard input twice. Delete one of those lines

Use either DirectX or OpenGL for game engines. Post game questions in the game forum.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If he can only use C constructs then c++ object oriented programming is not useable ether. This thread should be in the C forum, not c++.

If the program is running on a non-standard linux, then my statement is still true. He's running non-standard linux, which is not the same as linux. I've had to work with versons of MS-Windows on embedded systems that didn't support C's FILE structure and related functions or c++ fstream -- had to use win32 api file functions. But that wasn't a true MS-Windows OS either.

If the OP is talking about embedded programming then he needs to say so. Embedded C and C++ compilers do not have to adhere to the same standards as other c/c++ compilers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

@mike: You're right of course, as always.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In Forms designer, double click on the button and the IDE will generate an OnClick event handler. Then just add the code shown below.

#include "Form2.h"
<snip>
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 Form2^ form2 = gcnew Form2;
                 form2->Show();
             }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I can't use iostream (not linux compatible)
Who the hell told you that lie? (its just a rhetorical question, not meant to be answered here)

So you mean that you are really writing a C program, not c++. In that case std::map and std::string can not be used.

As for switch statements, I agree with firstPerson for simple cases. Switch statements only work with integers, not strings.

Using lookup table as described by Ketsuekiame would be the most efficient way to solve the problem, assuming all functions have the same parameters.

That leaves only one other alternative -- a series of if statements.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

@Sky: But that's not answering the OP's question. I think he wants to use the string class that's in STL. Writing your own isn't the same thing, nor would it even be desireable outside the adademic area of a university.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 332: You can't use strcmp() with String^, use == operator to compare it with another string just like you would with std::string.

Here is how to convert from String^ to int.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

@firstPerson: That's because YOUR compiler lets you do that. vc++ 2010 will not.

@Sky: You still have to include the header file for your version of the string slcass. So its not even "technically possible". You need to include the string header file regardless of whose class it is (or put your class declaration in the *.cpp file that uses it)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

One way to do it is to do two finds

size_t found1=0;
size_t found2=0;
found1 = aDir.find_first_of(search_char);
cout <<"@ is found at:"<<found1<<endl;
if (found1!=string::npos)
{
    cout<<"now :"<<aDir <<endl;
    found2 = aDir.find('-', found1+1);
    aDir = aDir.substr(0,found1) + aDir.substr(found2-1);
}

Of course you may need to do it a little differently if the second find fails, such as use temp strings to old the sub strings.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

deleting the last node incorrectly

void LinkedList::deleteLastN(int n)
{
    nodePtr currPtr = head;
    nodePtr prevPtr;
    int length = size() - n - 1;
    // keep the value returned by size() in a local
    // variable so that it doesn' have to be recalculated
    // on every loop iteration.
    for (int i = 0; i < length; i++)
    {
        currPtr = currPtr->next;
    }
    prevPtr = currPtr;
    currPtr = currPtr->next;
    prevPtr->next = NULL;
    while (currPtr != NULL)
    {
        prevPtr = currPtr;
        currPtr = currPtr->next;
        delete prevPtr;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Populate struct tm with the date, set the time to some fictious number (if you don't do that the next step will fail), then call mktime(), which will populate all the rest of struct tm and return time_t value.

You will have to parse the string to extract the year, month and day. When you populate the struct tm you have to subtract 1900 from the year, and subtract 1 from the month.

struct tm can only handle a limited number of dates. You can not force it with a date before 1900.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The operator >> isn't quite right. A common problem of using eof() incorrectly. The way you have it coded the function will read the last line twice and insert the same number twice into the list

istream& operator >> (istream &sourceFile, LinkedList &list)
{
   elementType nextElt;
//   sourceFile >> nextElt;
//   while (!sourceFile.eof())
//   {
//      list.insert(nextElt);
//      sourceFile >> nextElt;
//   }
   while( sourceFile >> nextElt )
       list.insert(nextElt);
   return sourceFile;
}

Next: insert

bool LinkedList::insert(elementType elt)
{
    nodePtr newNode = getNode(elt);
    if (newNode == NULL)
        return false;
    if (head == NULL)
        head = newNode;
    else
    {
        nodePtr currPtr = head;
        nodePtr prevPtr = NULL;
        while (currPtr && currPtr->item < newNode->item)
	    {
            prevPtr = currPtr;
            currPtr = currPtr->next;
        }
        // 
        if( currPtr == NULL)
        // If at end of list, just add the new node
        // to the tail of the list
        {
            prevPtr->next = newNode;
        }
        else
        {
		    newNode->next = currPtr;
            if( prevPtr == NULL)
                // If at the head of the list,
                // add the new node to the head
                // of the list
                head = newNode;
            else
                // insert the new node
                // somewhere in the middle of the list
                prevPtr->next = newNode;
        }
    }
    return true;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Console::Read() only reads a single key from the keyboard buffer. When you type 'Y' followed by a <Enter> key there are two keys, not one, in the keyboard buffer. You have to remove the '\n' so that Console::Readline() can work properly.

One way to fix that is to use Console::Readline(), not Read() to get the 'Y' or 'N' response. Another way is to flush the keyboard buffer of all keys by calling Console::Read() in a loop until it returns '\n',

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The docs are scarce for VARIANT types. bval is a BYTE (unsigned char) value type. You have to look in the header files where VARIANT is declared.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> have any answers?
Yes. Your posting this in the wrong forum. This is Geek's Lounge, not a hardware support forum. You are likely to get a lot of smart-assed answeres here.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The while statement on line 96 isn't quite right. It needs to check for end of list, such as the value of elt is greater than any value in the list. In that case the loop will continue beyond the end lf the linked list.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>if (Gavity.Text == 'Heavy' || 'Normal' || 'Low'){
That isn't a c++ legal statement, manage or unmanaged. if( Gavity.Text == "Heavy" || Gavity.Text == "Normal" || Gavity.Text == "Low"){ I created a simple Forms application with a combo box and a text box, then copied the selected item in the combo box into the tex box. Works perfectly, so you should be able to adapt it to your problem. The last few lines of the code below is only what you will probably need. I just posted the whole file just in case you need it.

#pragma once

namespace FormsText {

	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
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
    private: System::Windows::Forms::ComboBox^  comboBox1;
    private: System::Windows::Forms::TextBox^  textBox1;
    private: System::Windows::Forms::TextBox^  textBox2;
    protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#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->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
            this->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->textBox2 = (gcnew System::Windows::Forms::TextBox());
            this->SuspendLayout();
            // 
            // comboBox1
            // 
            this->comboBox1->FormattingEnabled = true;
            this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^  >(10) …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post the whole program -- I'm not going to guess any more.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You must be doing something else that causes that '\n' at the end of the string. This works ok for me

int main()
{
    char *argv[20] = {0};
    std::string ip = "127.0.0.1";
    argv[1] = (char*)ip.c_str();
    std::cout << argv[1] << '\n';
    std::cout << "Hello\n";

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

maybe its the compiler you are using. Try it with a good current compiler such as Code::Blocks with MinGW compiler or Microsoft VC++ 2010 Express -- both are free.

I just compiled your program with vc++ 2010 express and did not have the problem

#include <stdio.h>

#include <fstream>
#include <iostream>
#include <conio.h>
#include <string.h>
using std::ofstream;
using std::cout;
using std::cin;
using std::ios;
using std::endl;
#pragma warning(disable: 4996)

void clrscr()
{
    system("cls");
}

int main()
{
  clrscr();
  int k=0;
  char p[30], u[30], c=65;
  cout<<"USERNAME: ";
  cin>>u;
  cout<<"PASSWORD: ";
  // for hiding the password entered
  while(k<30)
  {
    c=getch();
    if(c==13)
    break;
    p[k]=c;
    clrscr();
    cout<<"USERNAME: "<<u;
    cout<<"\nPASSWORD: ";
    for(int i=0; i<=k; ++i)
    cout<<"*";
    k++;
  }
  ofstream ofile("blog.abc", ios::app);
  ofile<<u<<endl;
  ofile<<p<<endl;
  cout<<"\n SUCCESS ";
  getch();
  ofile.close();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

don't do that :)