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

you need to keep up with lastest compiler technologies -- if you don't you will find yourself quickly obsolete.

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

greetings folks,


#include<stdio.h>
#define T t
void main()
{
char T = 'T';
printf("\n%c\t%c\n",T,t);
}

just check what is the output of this program
and puhleease tell me reason whyit happens so??
:rolleyes:

compile and run that program, then you will see for yourself what the output is. Why does it happen? Because T and t are both the same thing. The #define statement at the top of the program tells the compiler that T is just another name for t.

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

the PGM structure passed to readPGM is uninitialized -- all members contain random values. Yet readPGM is attempting to allocate an array of doubles based on these worthless values in nc and nr structure members.

v.pix = new double[v.nc*v.nr];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

unichar can be more than 2 bytes? I thought it was always 2 bytes.

The size of wchar_t is operating system dependent. On MS-Windows wchar_t is defined as unsigned short. *nix computers it is unsigned long. And the UNICODE standards say that they intend to have 64-bit wchr_t.

That becomes a very big problem when attempting to port a UNICODE file between operating systems.

smality: No sure if this will help or not.

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

please describe the problem -- what does the program NOT do that it should? Are there any compiler errors? If yes, that are they. Runtime errors? What are they.

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

thats not going to work, I'm putting them into a storage and then calling a function.

while(infile >> temp->name >> temp->age)		
  {
insert(); // call the function
}

the while loop no longer calls insert... and if im wrong it wont do it for each line?

you are wrong -- that loop will read each line until end-of-file is reached (assuming each line contains name and age). Call whatever functions you want within that loop. You can pass temp to insert() if insert() needs the information.

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

In order to sort, you first need an array of structures. Linked lists can be sorted, but much more difficult than arrays.

struct tuple array[NumTuples];

Now, after filling in all the array elements, you want to pass to function bubble and sort by Year. In the case of arrays, its a lot faster to sort an array of ints that represent the index values of the array of structures.

int bubble(int x[],struct tuple array[], int n)
// function is going to sort array[] indirectly by use of integer 
// array x[].
{
   int i,j;
   for(i = 0; i < n-1; i++)
   {
       for(j = i+1; j < n; j++)
       {
           if( array[x[i]].Year > array[x[j]].Year)
           {
                  int hold = array[x[i]].Year;
                 array[x[i]].Year = array[x[j]].Year;
                 array[x[j]].Year = hold;
           }
        }
    }
     return 0;
}

int main()
{
   int i;
   struct tuple array[NumTuples];
   int indexs[NumTuples];
   // initialize indexes
   for(i = 0; i < NumTuples; i++)
        indexs[i] = i;
   // sort the array
   bubble(indexs,array, int NumTuples);
   // print each elment
   for(i = 0; i < NumTuples; i++)
       printf("%s\n", array[indexs[i]].artist);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you should normally use a loop to read all the lines of a file. For example

while( infile >> temp->name )
    cout << temp->name << endl;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The files can be created with fopen() function. Here is a description of the function (not a tutorial). There isn't really much to it: To open for output (destroys the fle if it already exists).

FILE* fp = fopen("myfile.txt","w");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

disregard pervious post, i fiddled around and got it to work. However I'm struggling to figure out how to get the next line of fields?

Our crystal ball is out of order today. Guess you'll have to post your new code :p

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

I don't know which line contains the error, but you don't use strcmp() when comparing std::string object to something, just use its == operator

int Bank::FindAccountbyNumber(string accnum)
{
for (int j=0;j<Accs.size();j++)
{
 if (Accs[j]->getNum() == accnum)
 //if (!strcmp(Accs[j]->getNum,accnum))
  return j;
}
return -1;
}

once you have fixed that the compiler will probably produce a link error because you haven't coded function Bank::DisplayAllAccounts().

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

thanks

>>>>local function definitions are illegal

how can i fix this i did not found any error

and please if you know how to complete it

function withdraw() is missing a closing brace'}'.

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

you are going about this the hard way. This is a c++ program -- stop using C character arrays :mad:

You don't have to read the bloody file one character at a time. fstream has operators and functions that will read entire words or numbers into your program for you. All you have to do is learn how to use them. For example

int n;
infile >> n;

That will read an integer directly into the variable.

std::string last_name, first_name, mi;
infile >> last_name >> first_name >> mi;

or you can put all the above all on one line

std::string first_name, last_name;
int age;
infile >> first_name >> age >> last_name;

and use infile.is_open() to test that the file was opened ok, infile.fail() may not work as expected.

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

try to fix the errors one at a time. Take the first error for example. It says there is something wrong on line 77, which is nothing more than "};". Nothing wrong there, so the prioblem must be above that line. Look at line 76 -- what's wrong with it? It looks as if its a POD (Plain Old Data) data type, but you can't declare a POD of type void, so I suppose you indend for setOpType to be a function. If its a function, then its missing "()" and the semicolon at the end. Fix that problem then recompile, that will probably fix some of the other errors. Then do the same with the other errors until you get a clean compile. Its just a matter of learning to recognize mistakes in your code. The compiler gives you a hint where to look and the problem is almost always in that line or the line above.

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

hmmm. ...

I deleted my previous objection -- my error.

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

Ok -- so it can be done.

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

questions 3 and 13 are identical. Both questions use undefined behavior of data overflow, so results will also be undefined.

Write a "Hello World" program in 'C' without using a semicolon.

Not possible.

Write a C++ program without using any loop (if, for, while etc) to print numbers from 1 to 100 and 100 to 1;

use recursion

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

The error should be pretty obvious -- it cannot find the quoted file. Search your compiler's lib directory for it. If it isn't there, then I don't know how you can get it. If it is there, then all you have to do is tell your compiler where it is. How to do that depends on the compiler you are using.

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

cout << buffer -- buffer needs to be a null-terminated character array. when you defined buffer you did not initialize it to anything, that means it contains random characters and the buffer may or may not contain a null-terminating 0. So cout just keeps displaying characters searching all memory for the first 0, which may be considerably beyond the end of the buffer.

To avoid that problem, declare buffer like this

char buffer[20]  = 0;

That will fill the buffer with all 0s.

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

I don't know if this will help, but try here

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
node[5]->key = key;

That is wrong syntax. you have to use dot notation, not pointer notation because node[5] is NOT a pointer.

node[5].key = key;

If done this way I don't have to allocate memory to node[5]->key before setting it equal to key right?

Well, maybe yes and maybe no. How is paramater key being allocated? Will the calling function reuse that memory for something else, such as does it get overwritten each time the insert function is called or is new memory allocated each time?

I find it normally best to reallocate the memory so that node has complete control over it and not count on some other function allocating/deallocating node's memory.

eg. void *insert(void *key, long keysize)
{
node[5].key = malloc(keysize);
memcpy(node[5].key,key,keysize);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

years ago before anyone heard about namespaces programmers had a terrible time avoiding name conflicts in their own code and the libraries they used. That was the main reason (I think) for the introduction of namespaces -- you can have as many objects with the same name as you wish as long as each object is contained in a different namespace. you will commonly see code such as

std::cout << "Hello Worod" << std::endl;

This is identifying the namespace (std) of cout and endl. For objects in global namespace, such as all the win32 api functions just preceed the object with two colons as in the following code. This is really more useful when there is another function called MessageBox() in another namespace that your program also might use. Its just telling the compiler which function to call.

::MessageBox(0,"Hello World","Message",MB_OK);

c++ classes have the same affect as formal namespace

class MyClass
{
   MyClass();
   static void SayHello() {std::cout << "Hello World" << std::endl;}
};

// call the SayHello method
MyClass::SayHello();
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

About color check, Ancient Dragons post, that was what I was talking about...

very similar to code tags but use color tags insted
[ color = <color here> ] and [ /color ]
(remove the spaces from the above)

Example in red

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
#include <iostream>
#include <fstream>
using namespace std;

int main()
{

	fstream fin;
	char fileName[21];<< MS-Windows filenames can be 255 characters
	char line[500];
	char string; <<< this is NOT a character array, only ONE character

	cout << "Enter the name of file you wish to open: ";
	cin.getline(fileName, 21);
	if(!fin)
	{
		cout << fileName << " could not be opened. \n";
		return 0;
	}
	int lines = 0;
	cout << "Enter your search string: ";
	cin >> string;<< use getline() here so that the
search string can contain spaces
What is the below for?  useless.
	if(string > 65 && string < 122) << ?????
	{
        fin.seekg(0,ios::beg);
		cout << string << endl;
		lines ++;
	}
Well you now have the filename, so you need to
declare an object of type ifstream, open the file, read each line, search the line for the search string
and finally close the file.  Looks like you still have some work
ahead of you.	  
   
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

TASM 5.0 is a MS-DOS 6.X and earlier 16-bit assembler and will not assemble 32-bit code that is needed for MS-Windows.

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

Sorry, I hit "enter" and prematurely posted. Edited!

I hate it when I do that :cheesy:


try moving the clear line after closing the file. This works ok.

int main()
{
	string line;
	ifstream in("myfile1.txt");
	if(in.is_open())
	{
		while(!in.eof())
		{
			getline(in,line);
			cout << line << endl;
		}
		in.close();
		in.clear();
	}

	in.open("myfile2.txt");
	if(in.is_open())
	{
		while(!in.eof())
		{
			getline(in,line);
			cout << line << endl;
		}
		in.close();
		in.clear();
	}
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You forgot to ask the question? :lol:

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

Hi,
Thank you very much for your reply.
i did use Sleep(20) but it doens't seem to work. Is there a wrong or a right way to do it? i am also wondering if the sleep fnc c?

gmv

What makes you think it doesn't work? 20 milliseconds is not a very long time :eek: During the sleep period you program get no cpu time because the os's thread scheduler does not give it any. However, MS-Windows os is not rocket science, so don't expect the sleep period to be very exact -- meaning that the program may sleep anywhere from 1 to 200 or so milliseconds.

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

something like this. However this will not prevent somebody from entering more than 7 digits or from entering other characters.

int c;
int array[7] = {0};
int counter = 0;

while( (c = getchar()) != '\n')
{
   if( isdigit(c))
       // put the binary number in the array and bump the counter
       array[counter++] = c - '0';
}

or you could use fgets() to get the entire string, then validate that it contains the right number of digits and a hyphen

char input[9];
fgets(input,sizeof(input),stdin);
// does it contain a hyphen
if( input[3] != '-' )
{
   // display an error message
}
// count number of digits
for(counter = 0, i = 0; input[i]; i++)
{
   if( isdigit(input[i]))
     counter++;
}
if(counter != 7)
{
   // display error message
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

ok, thanks. The only part that worries me is the teacher is pretty strict on the code format, if we use different methods than what he wants he will make us change it. The teacher has made errors before in the instructions but it says the array needs to be 7 integers. isdigit() was mentioned to be used, I know nothing about it, and I assume isdigit needs a char type?

isdigit() returns true if the character is '0' through '9'

char c = '1';
if( isdigit(c) )
  printf("Its a digit\n");
else
  printf("Its not a digit\n");

now, all you have to do is loop through the input string and place each digit into the next available array element. If isdigit() returns false (0) then do nothing. That will mean you will need to keep a counter variable to keep track of where in the array to place the digit.

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

correction -- need to double-slash for the compiler.

system("C:\\Program Files\\PowerMenu\\PowerMenu.exe -hideself on");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you don't need to call cmd.exe explicitly -- the system() function will do that for you. All you have to do is tell system() what program you want to run

system("C:\Program Files\PowerMenu\PowerMenu.exe")
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

sorry but i do not know how to make what you say
i want this program to design my program which written in c++ language

everything I mentioned can be used by C++. Its just that they are all somewhat difficult to use and will require a solid understanding of c++ language, not really intended for newbes :rolleyes: Afterall you can't play a Beethovan's Concertos if you know nothing about music, so what makes you think you can write complicated graphics programs with no (or little) knowledge of a programming language?

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

that may be fun to write, and you will most likely learn a great deal from it, but you should learn to use standard c++ or C functions, afterall that's why they are standard.
For example, here is how to convert an int into string with no effort

#include <string>
#include <sstream>

int main()
{
   int n = 12345;
   std::stringstream s;
   s << n; // convert to string
   cout << s.str() << endl; // output the string 
   
   return 0;
}

ok, so maybe you want to put it in a character array instead of displaying it

#include <string>
#include <sstream>

int main()
{
   int n = 12345;
   char array[20];
   std::stringstream s;
   s << n; // convert to string
   strcpy(array,s.str());
   cout << array << endl; // output the string 
   
   return 0;
}

Now, the above program contains 3 executable program lines. How many does yours contain, that does nothing more than what I did?

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

thanks you mean that i can not use this library
would you give me another one please

The days of directly accressing windows memory are gone! For MS-Windows, there is OpenGL which I think is free, DirectX and DirectDraw, both free from Microsoft. All are very complex libraries.

you can also call win32 api functions to draw graphics. I think you can find several tutorials if you google for them.

There is also QT, which is a os-independent way of going graphics. Free for home use, but not free for commercial use.

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

So?

system("cls") is non-standard and doesn't work across operating systems -- for examp unix uses system("clear"), and I suppose apple uses something else. If you want to write ANSI C or C++ then you must stay clear of system() function. But you can ignore that little detail when writing small example programs for yourself that you never indend for anyone else to see.

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

system() function takes a lot of time to execute. There are better ways to do that which do not use cmd.com (or command.com).

c++ -- cin.ignore() will wait for user input
 or cin.get()

c -- getchar()
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

one way would be to write into autoexec.bat to delete the program, then reboot the computer.

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

graphics.h was non-standard 16-bit Borland compiler specific. M$ compilers never supported it. You will probably have to download free copy of Turco C to compile that program.

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

Again, why is it an undefined behaviour?

any time you use os-specific os-internals, it becomes undefined behavior because c and c++ standards do not specifiy what should happen. It might not have that behavior on another operating system.

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

no, I don't know how to get the physical address of the stack segment. there is probably a win32 api function somewhere that will give it do you.

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

The change in printf() doesn't really make a difference. The memory allocated is always the same. It does concern the OS, but how can the same memory location be allocated to two variables at the same time?

Not certain, but the address you see is probably the offset from the beginning of the program in memory, not the real address of the variable in your computer's memory.

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

using the >> operator, cin will split up the text for you. In the code you posted, if you display the value of details variable you will see that it only contains the first "word". If you typed "John 19 10 06 1986", details will contain only "John". you will need other variables to store the other words, for example (you should use better variable names than I do in this example -- I don't know what those variables mean)

string name;
int n1,n2,n3,n4;
cin >> name >> n1 >> n2 >> n3 >> n4;

or if you want all of them in "details", use getline()

string detils;
getline(cin, details);

Now, getline will contains all the words. You can use std::string's find method to locate the spaces and use std::string's substr method to extract subsections of the string.

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

delete all these lines

#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;

and replace it with this

#include <stdio.h>

replace c++ references with pointer, for example

void Process(int *scoresArrayPtr, int numOfScores,
             int& highestScore, int* lowestScore,
             double* averageScore);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you could just use MessageBox() function, which is used for most error messages. You won't get an SOS button though.

MessageBox(0,"Once again your soul is ours!","Owned by IT Support" , MB_OK | MB_ICONEXCLAMATION);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

See this tutorial

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

learn to use your compiler's debugger and single-step through the code so that you can see what is going on. It's better than just guessing.

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

nothing in MS-Windows programming is "simple". If you want "simple" then stay with console programs. The function FillListBox() that was previously posted looks simple to me -- only 3 program lines. The rest of that post is common code that is required by all MS-Windows program using win32 api functions.

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

That may be true, but you should know that I had been using MFC exclusively for the past 3+ years...sigh... I had only found out about fltk and gtk within the past few months.

-Fredric

Could it be that I've been suckered (brainwashed) by M$ into thinking MFC was a great product :mrgreen: I write a lot of code for WinCE 5.0 so there isn't much choice for me.

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

http://www.parashift.com/c++-faq-lite/templates.html#faq-35.16

Great :mrgreen: coding the friend function at the time it was declared solved the problem.

template <class Type>
class doublyLinkedList
{
    friend ostream& operator<<(ostream& os, 
                           const doublyLinkedList<Type>& list)
{
    nodeType<Type> *current; 

	current = list.first;  

	while(current != NULL)
	{
	   os<<current->info<<"  ";  
	   current = current->next;
	}
	return os;
}

// rest of class here