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

Your compiler did not lie to you -- variable low is being used before it as initialized with a value. At that time the variable contains just some random value, whatever was left in the memory location. How to you fix that? Just initialize it when it is declared, e.g. int low = 0;

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

Looks solved to me :) Maybe you just need to refresh your browser.

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

Attached is a HelloWorld program I created. Unzip it on your computer then load the solution and try to compile/link it.

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

Please read this thread and see if it helps you.

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

Is this the first console program you have written since installing that compiler? Maybe you have a configuration problem.

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

Did you code a main() function?

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

For each letter in the source string you have to check each character in the vowels or conconants string to see if the letter in the source string matches one of those.

// count vowels
times = 0;
for(; *str != '\0'; ++str)
{
   for(vowelsptr = vowels; *vowelsptr != '\0; vowelsptr++)
   {
      if( tolower(*str) == *vowelsptr )
      {
          ++times;
          brak;
      }
    }
}

Another, even simpler way to do it is to use strchr(), if you are allowed to use that function

times = 0;
for(; *str != '\0'; ++str)
{
   if( strchr(vowels,*str) != NULL)
       ++times;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'd replace that old compiler with a newer one, such as Code::Blocks or VC++ 2010 Express. Dev-C++ has not been supported or updated for many years now, and the distribution contains an old obsolete version of MinGW compiler.

Aside from that, the error you got was probably because that header file was not in the same directory as the rest of the source code files.

Attached is the project I created using VC++ 2010 Express. I deleted all the compiler-generated files to make the *.zip file smaller

lexusdominus commented: very informative and helpful +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, I agree with Sfuo -- you can add MS-Windows gui to a console application. Here's how to do it from the console program. What I did was create a win32 windows application then copied the *.cpp, *.h, *.rc and other resource files into the console project folder, then add all those files to the console project. I even left tWinMain() in tact, just as the VC++ 2010 Express IDE generated it. I changed nothing in the GUI program. Then I put the GUI startup into its own thread so that the GUI would run at the same time as the console program.

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{

    HMODULE hInstance = GetModuleHandle( (char *)lpParameter);
    _tWinMain(hInstance,NULL,(char *)lpParameter,SW_SHOW);
    return 0;
}

int main(int argc, char* argv[])
{
    DWORD dwCounter = 0;
    DWORD dwThreadID = 0;
    HANDLE hThread =  CreateThread(NULL,0,ThreadProc,argv[0],0,&dwThreadID);
    while(true)
    {
        // your actual console program may not have to call WaitForSingleObject()
        // I just put it here so that I could easily see the console displaying
        // something while the gui is running.
        DWORD dwReturn = WaitForSingleObject(hThread,2000); // 2 second wait
        if( dwReturn == WAIT_OBJECT_0 )
            break;
        cout << "counter = " << dwCounter << '\n';
        ++dwCounter;
    }
    cout << "All done folks\n";
    cin.get();
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>... Could VC++ just tell me?!?
I think it did -- you just were not listening.

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

line 40 is wrong -- as posted it is just a simple global function, which is unrelated to the Tree class. You need to add Treed:: before the function name, similar to what you did on line 29.

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

A tripple pointer can mean one of two things:
1. A pointer to a 2d array. In this case the 3d star is not used in the calculation

2. A 3d array -- each dimension is calculated like I mentioned previously.

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

The compiler must know one of the dimensions in order to calculate the location of any specific double value. If it was only given ** with no other information how could the compiler possibly calculate the location of a[2][5]? In order to calculate that location you have to know the number of doubles on each row of the array, if the array is declared a[10][10]; then the compiler calulates it something like this: a (start of the array) + 10*sizeof(double) (number of bytes to start of 2nd row) + 5*sizeof(double) (number of bytes from start of 2nd row to 5th element)

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

Thanks for the clarification -- just goes to show how little I really know about it :)

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

It doesn't work because variable a is not a pointer, its an array. Try this int foo(double [][10] )

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

using vc++ 2010 there are a couple options
1. Create a win32, Win32 Project. That will generate a shell of a program in which you will have to code all the window stuff using pure win32 api graphics functions. Here is a tutorial to get you started with that. Be forwarned that you will have to write a lot of code just to do the simplest things.

2. Create a CLR Windows Forms Application. This is mostly visual drag-and-drop to design the visual forms the way you want them. Then to make a control such as a button do something all you have to do is double click the button and add the code you want in the function that the IDE will provide for you. This is called managed c++ and is a little different than standard c++. Here is a list of several tutorials.

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

It does work -- maybe you are just doing it wrong. Post the code that doesn't work right for you. If you want another function to allocate all that memory then you will have to pass it with three stars, not two

double** foo(double ***array) 
{

   return array;
}

int main()
{
   double** array;
   foo(&array);
}

or you can use the c++ reference operator instead of a third star

double** foo(double**& array) 
{

   return array;
}

int main()
{
   double** array;
   foo(array);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>We can not use a double pointer(int **) for a two dimensional array, right
Wrong. Here is a brief example of how to allocate such a thing.

int main()
{
   const int numRows = 5;
   const int numColumns = 10;
   double** pointer = new double*[numRows];
   for(int i = 0; i < numRows; i++)
       pointer[i] = new double[numColumns];
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Read the entire file and extract the column(s) you need. I would use fgets() to read a line, then strtok() to split it into individual columns.

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

You will have to post the code for that function, but the error message means you can not do something like this

char* foo()
{
   char data[25] = "Hello World";
   return data; // error because data is a local variable
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

add another variable to keep track of the element number and use it just like you do highTemp variable that appears on line 6 of the code you posted.

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

And many new ones have cell phones pre-installed and ready to go any time day or night.

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

Got to admit my system is getting pretty old too, but has been very reliable throught the years with few breakdowns and no hard drive crashes. If this one stops working permanently I'm not going to bother with a new one because it will take too much time to educate and train it the way I want.

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

LOL: Very similar to the one about upgrading from girlfriend to wife.

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

1>------ Build started: Project: test1, Configuration: Debug Win32 ------
1> test1.cpp
1>c:\dvlp\unmanaged\test1\test1.cpp(2): fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Notice the second line tells you what's wrong. Then if you removed the .h file extension your compiler should have given you these messages

1>------ Build started: Project: test1, Configuration: Debug Win32 ------
1>  test1.cpp
1>c:\dvlp\unmanaged\test1\test1.cpp(51): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
1>c:\dvlp\unmanaged\test1\test1.cpp(55): warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\conio.h(128) : see declaration of 'getch'
1>  LINK : c:\dvlp\unmanaged\Debug\test1.exe not found or not built by the last incremental link; performing full link
1>  test1.vcxproj -> c:\dvlp\unmanaged\Debug\test1.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1. Yes
2, 3, and 4 -- I don't know
5. With a compiler. For MS-Windows you have several choices, such as Code::Blocks and VC++ 2010. For *nix normally compile with gcc, which is on most *nix computers. C programs have to be compiled for the operating system in which it will run, unlike scripting languages such as HTML.

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

add function prototypes at the beginning of the program, before the first function in the *.cpp file but after includes.

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

lines 30 and 32: You are still trying to invoke a function incorrectly. do not put the return type before the function name. If you want to call menu() then just say mainu(); -- not int menu() Remember: putting the return type before the function name makes it a function prototype, not a function call.

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

lines 160-163. The functions in those statements are NOT function calls, but function prototypes. If your intent is to call a function then remove the return type int, for example case 1:view_balance();break; Delete line 60 because it does nothing.

Now, where in all that code are you tring to put the two lines of code You posted in your original post that gave you the problems?

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

You will have to post the full code of the program you are attempting to write.

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

you can move line 13 of the code I posted up above main(), but the other lines must be in a function.

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

Might be a permissions problem. Does your program check the success of opening the files, such as with stream.is_open() ?

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

lines 8, 9 and 10 must be inside a function

#include <string.h>

typedef struct electro
{
    char name[20];
    int access_number;
    char address[50];
    float balance_due;
    };

int main()
{
    electro account[10];
    account[0].balance_due=120.52;
    strcpy(account[0].address, "Cane Gardens");

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

I just gave you an example.

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

If you want to keep the data for each line separated then use a 2d array or 2d vector and declare it above that while loop that starts on line 20. float data[25][20]; is large enough to hold the data for 25 lines of code. Change the 25 to whatever you need for the data file the program is reading.

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

you have to tell the compiler that ifstream and ofstream are in std namespace. There are a couple ways to do that

#include <fstream>

using std::ifstream;
using std::ofstream;

or this

#inclue <fstream>
#include <iomanip>

int main()
{
   std::ifstream fin;
   std::ofstream fout;
}
beejay321 commented: think that did the trick thanks! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The struct tm in time.h or ctime contains an integer that represents the day of the week. After getting the date from the keyboard just fill in a struct tm and pass it to mktime() to complete the structure. You must zero out all the elements of the structure before doing that.

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

Just rename the *.bak files to *.c (or whatever the original file name is). *.bak files are identical duplicates of the original. You will most likely have to exit your compiler's IDE before doing this.

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

You got -1 because mktime() also considers the hours, minutes and seconds fields of the tm structure. Just use memset() to initialize the structure to all 0 then fill in the year month and day

Also -- difftime() takes two time_t objects, not pointers to two struct tm objects.

#include <iostream>
#include <iomanip>
#include <ctime>
using std::cout;
using std::cin;

int main()
{
    struct tm oldTimePtr;
memset(&oldTimePtr,0,sizeof(struct tm));
oldTimePtr.tm_year	= 2000 - 1900;
oldTimePtr.tm_mday	= 1;
time_t oldTime = mktime(&oldTimePtr);
time_t now = time(0);
cout << std::fixed << difftime(now, oldTime) << '\n';
cin.get();

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

Did you compile and run that little program? If not, you should do it now so that you gain better understanding of what it does.

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

>>ohh, ok ancient the >> make read just the numbers,and not the line who begins with #(char variable) correct?

Yes, and that's why I added the getline() just before the while loop

What I posted will just read all the numbers, one at a time. You will have to add code that uses those numbers for something. I don't understand what you need to do with those numbers.

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

The string line is correct -- its derived from std::string declared in <string> header file. You should compile and run the program yourself to see what >> does.

#include <iostream>
#include <fstream>
#include <string>

int main () {
  std::string line;
  std::ifstream is;
  float num;
  std::cout << "Enter the name of an existing text file: ";
  std::getline(std::cin, line);
  is.open (line.c_str());        // open file

  // get the first line
  std::getline(is,line);
  // how get all the rest of the numbers
  while( is >> num)
  {
     std::cout << num << '\n';
  }
  is.close();           // close file
  
  cin.get();
  return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 13: variable str was declared on line 3 to have only 3 characters, yet you expect someone to type up to 256???? Also, use cin.getline(), not cin.get() because getline() will allow you to enter spaces.


The syntax in the loop is incorrect. ifstrezam will make all conversions for you if you use >> operator.

float num;
std::string line;
getline(is,line); // get the first line, e.g. #S 1
while( is >> num )
{
   cout << num << '\n';
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to use a keyboard interrupt -- int 16h. Put it in a loop, saving each character in your own buffer, until user presses the Enter key. I would make this a separate function. You will have to check that user does not type spaces in the path because 16-bit code can not handle them.

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

The out instruction outputs just one byte -- such as al. In the code you originally posted change out ax to out al

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

USERPROFILE environment variable works for me with Windows 7

#include <iostream>
using std::cout;
using std::cin;

int main()
{
    char* p = getenv("USERPROFILE");
    if( p )
        cout << p << '\n';
    else
        cout << "USERPROFILE not found\n";
    cin.get();
}
MasterGberry commented: Perfect C++ Example :) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>The tiny font makes it too easy to ignore

That was my first impression too. Large, bold text -- slap them in the face with it.

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

So sorry -- I was thinking of mov not out.

Are you writing inline code in a C program? I see you are using 0x3c8, which is C styly way or writing a hexidecimal number, instead of 03c8H, which is assembly way of writing it.

What C compiler are you using? out istruction is not valid with any 32-bit compiler but ok with 16-bit compilers such as Turbo C.

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

use a register for destination

mov ax,0
mov di,03c8H
mov word ptr [di],ax
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why is it checking to see if den == 1? What does that have to do with whether its negative or not? if(num||den < 0) That line is wrong. Should be if(num < 0 ||den < 0) . The previous if statement on lines 112-119 is meaningless.