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

are you sure you don't mean:

Otherwise the return value is undefined (where it is not explicitly 0).

No its not undefined -- the last else statement will take care of that case. The line you added will never get executed.

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

What compiler do you have? And what operating system. Your program gives me the same as the code I posted. It must be a compiler and/or os difference. Also, my computer has 5 Gig RAM.

str1 a str2 o
-14
Press any key to continue . . .
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is the output for apple and apparel

str1= le str2= arel
11
Press any key to continue . . .

BTY: I used VC++ 2008 Express compiler.

If you don't get the above output then you probably don't have the same program that I posted. Copy this, compile and run it to see what you get.:

#include <iostream>
using namespace std;

int str_compare(const char *str1, const char *str2)
{
    if (*str1 != '\0' || *str2 != '\0')
    {
        if (*str1 != *str2)
        {
            if (*str1 > *str2)
            {
                cout << "str1= " << str1 << " " << "str2= " << str2 << endl;
                return *str1 - *str2;
            }
            else if (*str1 < *str2)
            {
                cout << "str1 " << str1 << " " << "str2 " << str2 << endl;
                return *str1 - *str2;
            }
        }
        str_compare(str1 + 1, str2 + 1);
    }
    else return 0;
}	

int main(int argc, char* argv[])
{
	int x = str_compare("apple", "apparel");
	cout << x << "\n";
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> but what else can I do to put in CR and LF to the end of strings?
simple

char str[100] = "a string";  // see Salem's post #2 for this line
strcat(str, "\r\n");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I pass "Hella" and "Hello" as the two parameters, and it returned -14. The "Hello" for both and it return 0. "Hello" and Helloa" return 14.

What two strings did you pass it from main() ?

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

My suggestion: toss it into the trash can and get another computer. Or if you're the techi type you might try replacing the motherboard.

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

It'd be nice to know what operating system you have and what kind of computer (or is it your mother-in-law you are talking about :) )

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

worked ok for me, after I fixed the bug

int str_compare(const char *str1, const char *str2)
{
    if (*str1 != '\0' || *str2 != '\0')
    {
        if (*str1 != *str2)
        {
            if (*str1 > *str2)
            {
                cout << "str1= " << str1 << " " << "str2= " << str2 << endl;
                return *str1 - *str2;
            }
            else if (*str1 < *str2)
            {
                cout << "str1 " << str1 << " " << "str2 " << str2 << endl;
                return *str1 - *str2;
            }
        }
        str_compare(str1 + 1, str2 + 1);
    }
    else return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I get the same error message that you reported, and I used Dev-C++ IDE instead of command-line compile. My suggestion for you is to split that project up and make a couple static libraries, or a DLL, out of most of those files. That way the linker doesn't have to deal with all those *.o files except as they appear in the archive libraries.

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

>>void main()
read this

As for your problem:

int main()
{
   int sum[256] = {0};
   ifstream in("filename");
   char ch;
   while( in.get(&ch) )
   {
         if(ch > 0)
             ++sum[ch];
   }
   // now just display all the rows in sum that are greater than 0
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think your meter's broken. Did you catch Palin's speech tonight?

WOW! She made a lot of good points.
On Obama :
"....this is a man who has authored two memoirs but not a single major law or reform - not even in the state senate."
"Victory in Iraq is finally in sight … he wants to forfeit."
"Terrorist states are seeking new-clear weapons without delay … he wants to meet them without preconditions."

She has experience as a leader and an executive - what have Obama or Biden done other than be in Congress?

I think the race is going to get more interesting in the coming weeks.

Yes she made a decent speech, but she isn't running for President.

>>what have Obama or Biden done other than be in Congress?
Make the same statement about a lot of past presidents, most notably JFK and LBJ.

Q: how many presidents were neither senators nor governors?
A: here

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

If you don't want to do that then you can email it to me. PM me and I'll give you my email.

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

how did you declare it in your vb program? what you posted appears to be correct. But you don't need both the *.def file and use of _dllspec(__export) -- all you need is one of them.

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

zip up the project and attached it to your post. I'll give it a try. Make sure you deleted all compiler-generated files first to make the zip file smalller.

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

Great :) clearing temp files fixed the problem.

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

This must be the same issue as this thread because I just downloaded Firefox 3 and the menus appear normally.

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

I had to change computers because my other one bit the dust a couple days ago (64-bit Vista/IE7). Now when I log into DaniWeb I can't see the mod menus in Coffee House -- see thumbnail.

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

Yes, we can HELP you but we will not write it for you. You have to write the program then post questions about what you don't understand.

I believe the first thing you need to do is design the contents of the data file. What data do you want to save and in what format. Then you can begin designing the program -- what menus do you want, do you want to use structures of c++ classes to hold the inventory data. What data items will they contain (normally the same as in the data file). What questions do you want to ask the user? How will the user enter the data?

You need to think about all these things before writing even one line of code. Write them down on paper (or Notepad) to make the design easier and clearer in your head.

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

I just finished compiling and linking with Dev-C++ with no problems after adding the libraries.

[edit]Posted this before I saw your previous post (solution) [/edit]

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

I just compiled/linked with VC++ 2008 Express without a problem.

What was the exact error message? What you quoted was only an indication that one or more errors occurred.

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

Because the pointer has not been initialized to anything. It just points to some random location in memory, which your program may, but probably does not, own. Before using a pointer you must initialize it to point somepace. For example:

int *pVar;
int number;
pVar = &number;
*pVar = 9;
William Hemsworth commented: beat me to it :P +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

flush is a function so you need to use () cout.flush() Try this macro #define PRINT(x) (cout << x << "\n" )

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

>> what would I name my file or doesn't it make any difference?
It doesn't matter -- name it whatever you want. Text files normally have *.txt extension, not *.dat.

>>So how do I have to call out this file in main?
With ofstream its not necessary to specify ios::out because that's the default. Same with ifstream. ifstream outMCSequentialFile( "calculations.dat");

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

That should tell you that nobody uses that editor. My advice is to scrap it and use something else to write your program.

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

The reason is because entering numbers leaves the '\n' (Enter key) in the keyboard buffer. cin.ignore() will just remove the '\n'. So you either need another cin.ignore() or do what you did and use cin.ignore(2)

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

I suppose you could use the time functions in time.h

time_t t1, t2;
t1 = time(0);
t2 = t1
while( (t2 - t1) < 1) // one second
  t2 = time(0);

You might also check the Boost time functions

Alex Edwards commented: Interesting indeed! =) +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Typical official communications between Canadians and their neighbours to the South.

Americans: "Please divert your course 15 degrees to the north to avoid a collision."

Canadians: "Recommend you divert YOUR course 15 degrees to the south to avoid a collision."

Americans: "This is the captain of a US Navy ship. I say again, divert YOUR course."

Canadians: "No, I say again, divert YOUR course."

Americans: "This is the aircraft carrier USS Missouri. We are a large warship of the US Navy. DIVERT YOUR COURSE *NOW*."

Canadians: "We are a lighthouse. Your call."

That is very funny, but I hope you realize that Canadians and Mexicans are also Americans. America refers to the North American continent, not the USA.

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

how was the file opened? as text or binary? If binary then the next line character(s) depends on the operating system. In MS-Windows/MS-DOS you need "\r\n". *nix just "\n" and MAC "\r". If the file is opened in text mode then the operating system will make the appropriate translation of "\n" to whatever it needs.

I tried your three lines and it seemed to work ok for me. Opened the file with Notepad.exe and it looked ok (except for the Chinese characters). What editor are you using? If not English language then find out what it expects as line feeds.

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

Maybe this article will help you.

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

This probably won't solve your problem, but ... Do you really need that vector? Why not just combine those two loops?

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

You should be able to call win32 api function SHBrowseForFolder()

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

The function top() returns a reference to the top element of the stack.

http://www.cppreference.com/cppstack/top.html

It does not return NULL, but returns a reference to the first object in the stack. Checking for NULL is not a valid thing to do.

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

why? The operating system does all the thread swaping for you.

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

No I can't because I know nothing about that editor. Go back to where you got it and see if they have a user's group or forum where you can ask questions. My pure guess is that you failed to include some header file(s). Compare your program with the code you said that works to see what it is missing.

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

What operating system? Is it something that you are writing ? I did something similar in MS-DOS 6.X (a program with multiple context threads). In that program I had a kernel function (kernel to my program) that pushed all registers onto the stack, switch stacks, then poped registers of the new thread. This did not require any context id's

I have no clue what your swapcontext function does, other than swap out one thread for another.

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

Learn to program it yourself. Or offer to pay someone in the Looking To Hire board.

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

Welcome to DaniWeb.

>>i need input on where to start
Sart at the beginning by talking to your college school consoler.

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

Did you try something like this?

#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;

void foo(ifstream& in)
{

}

int main()
{
    vector<ifstream*> streams;
    for(size_t i = 0; i < 5; i++)
    {
        ifstream* in = new ifstream;
        streams.push_back(in);
        streams[i]->open("filename.txt");
    }
    foo( *streams[1] );
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>are STL containers faster then c-style arrays?
No. you can't get any faster access than c style arrays. But that isn't the point -- c++ STL eliminate many of the problems with c style arrays, such as dynamic array allocations. vector and other containers expand/contract by themselves, and they always know their size, unlike c style arrays.

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

you can use either sprintf() or strcat() to format the output file name. Example:

char outname[255];
char inputname[255];
char* ptr;

printf("Enter a file name\n");
fgets(inputname,sizeof(inputname),stdin);
strcpy(outname, inputname);
// truncate the extension
ptr = strchr(outname,'.');
if(ptr != NULL)
   *ptr = '\0';
// now add new filename
strcat(outname,"_res.txt");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

moved

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

The error message is pretty clear about what is wrong, and the solution sould be obvious: where did you declare MUSHROOM_END ???

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

1) 2) and 3). Very little, if any, performance gain. Those are not areas to optimize because the compiler will do that.

4) You talking about c++ classes? vertual class methods are extremly handy and I've used them often at my work (before I retired that is).

>>the virtual functions are especially to avoid.
That just a bold-faced lie.

5) >> I was always told to avoid using global variables
Yes, absolutely. Globals should be avoided whenever possible, but there are times when its not possible to avoid them. MS-Windows GUI programs (especially MFC) is a prime example.

>>usually after being told never to use gotos
Agree. NEVER EVER (almost anyway) use gotos. There is almost always a better way to create a branch.

>>Does the compiler now adays do this lowlevel optimization
yes, at least it tries to. Optimizing compilers will even toss out code that it thinks does nothing and move code around to make the program more efficient. Some compilers are better at that than others.

7) Depends on the situation whether to use dynamic arrays or not. IMO it is better to just use statically allocated arrays for small arrays. Its even better to use std::vector or similar containers in c++ programs than c-style arrays.

>>Does it make a difference, or is it just academia
Probably does make a very very small difference, but its mostly academic. Readability, clarity, and maintainability are significantly more …

Alex Edwards commented: /salute +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

all c and c++ programs have a main() function, and it has two optional arguments. int main(int argc, char* argv[]) argc is the number of command-line arguments (deliminated with spaces). argc is always > 0 because the first argument is the name of the executable program.

argv is a character array of the arguments. argv[0] is (usually) lways the program's name

To if you type c:>myprog Hello World <Enter key> In the above, argc == 3,
argv[0] = "myprog"
argv[1] = "Hello"
argv[2] = "World"
.

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

That information is not in a *.ini file. Its in a database, such as MySQL and Microsoft SQL Server (there are lots of others too). The simplest kind of database is a plain text file. *.ini files only contain program configuration information that the user can change via an options menu, although it can contain other information too.

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

I don't have ubantu, but Microsoft VC++ 2008 Express reports 1 for the program that jamthwee posted. The compiler stored -61 in that byte. crappy *nix :)

>>I'm sorry, but I'm a beginner C++ programmer to such a "noob" level I don't know what you're talking about

UNICODE is a standard way to use non-English languages in computer programs. The standard UNICODE character is wchar_t, not char. Under MS-Windows wchar_t is defined to be unsigned short while in *nix (the last time I heard) it is unsigned long This is because many languages, such as Chinese, use graphic symbols which can be accommodated by wchar_t. In order to compile for UNICODE you have to set specific flags in the makefile -- I have no clue what those flags are for your compiler.

[edit]Considering jamthwee's test I would not bother with the UNICODE described above. It appears to be a compiler issue.[/edit]

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

Please post example code. Are you compiling for UNICODE ?

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

AFAIK Must be done in the constructor.

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

>>function(int *&head)
That is not a function that takes a 2d array. What you have there is a reference to a 1d array. They are not the same thing.

void functijon(int **array)
{
  array[0][1] = 123;
}

The above is a 2 dimensional array of integers. The first dimension is an array of pointers. You still have to allocate the second dimension before the above will work

int main()
{
    int **array;
   array = new int*[10];
   for(int i = 0; i < 10; i++)
  {
      array[i] = new int[20];
      for(int j = 0; j < 20; j++)
          array[i][j] = 0;
  }
}