jwenting 1,905 duckman Team Colleague
yes, several in fact.
you need to use an overloaded version of toArray() which takes as argument an array to put the data in (if it fits).
The usual way to use this version is as follows:
criteria = (String[])tokenVector.toArray(new String[0]);
which gives the function a zero-length array of String with the only purpose to use this array as an indication of the type of array you want it to return.
Alternatively you could initialise the array with the correct length and pass it:
String[] criteria = new String[tokenVector.size()];
tokenVector.toArray(criteria);
yes, that cost me about 5 minutes to deliberately get wrong ;)
ANd! To aDd to WhAT aLEx saId; pEAsE uSE prOPeR . punCtuATIon, ANd caPITaliSatION: IN yOuR quEstIonS?
read the old file, record for record.
Write all records to the tempfile, except the one(s) you want to delete.
Remove the old file.
Copy the tempfile completely to a new file with the same name as the old one.
Remove the tempfile.
Sure, and that's exactly how you should do it:
Create a textfile on disk.
Read in the file in your program. C(++) has full facilities for reading and writing any kind of file built right into the core language.
there's a function to do just that in the standard library by the name of atoi (ASCII to Integer).
steps:
1) order a large amount of coffee
2) order some pizzas
3) kickstart your brain
4) start thinking how you would solve it
5) write down your solution in words on a piece of paper
6) translate that into a flowchart and/or other diagrams
7) translate that into a functional model of your application
8) translate that into code
9) test and fix until working
Not just that, but unless you want to limit yourself to a very small library of functions indeed you're going to have to use compiler specific libraries at some point.
The trick is to use those libraries in such a way that the largest possible part of your code does not directly depend on them.
Example are GUI libraries. Those are pretty much all at least platform specific and often compiler specific as well.
Network libraries are the same, IO handling often as well (if you want more control than scanf and printf can handle).
gcc is no more generic than any other compiler, in fact it has a lot more platform specific libraries and some others and the documentation is often lacking.
In fact, Borland has always had the most standard compliant of all compilers on i386 platforms and a reasonably well marked custom library.
They also provide excellent documentation.
As to teachers being reluctant to change their material, often they aren't even aware they're using non-standard extensions, having learned C (or whatever) from the same book (Learning C in 21 days using Turbo C 1.5) they use to teach their students and never reading anything else.
NaN is typically the result of a floating point divide by zero.
So look at what might cause that...
You need no sorting at all in this scenario. Just keep an array of 4 ints and 2 ints.
For each int read check if it's larger than the one in which indicates the smallest and smaller than the one that indicates the largest.
If so, insert it into the array.
If not, replace the largest (or smallest) with the new value and put that old largest (or smallest) into the array.
When all are read add up the elements of the array and you're done.
There's no requirement to show the numbers from smallest to largest after all so why go to the trouble of getting them in that order in the first place?
uh, and what was the question?
why can't you use another compiler?
Cost can't be an issue as there are several modern compilers available free of charge.
Or are you stuck on a machine running DOS?
not at all a fetish, just overused by people that read tutorials by other people who abused it :)
There can be good reason to use it, for example if you were creating a fullscreen DOS application in Turbo Vision and wanted to clean up after yourself when terminating it.
and scrap #include "stdafx.h" as it's not needed... Never understand why MSVC adds that to everything.
Also add #include <iomanip> or you'll never get a clean compile. endl is defined there.
Look at the big button on your keyboard marked "Caps Lock". Press it until the CAPITAL LETTERS go away.
start by yourself then come back with specific questions.
Turbo C is a very old DOS compiler.
250*250 just happens to be very near the maximum value for a 16 bit unsigned int which is what under DOS is used as a pointer.
Use a 32 bit compiler if you want to allocate larger arrays.
ah, it's that time of year again.
About right, few weeks before the Christmas vacation...
P.S. posting in all caps is unlikely to get you more help. In fact it's extremely annoying and I won't read any post written that way.
P.P.S. read the posting guidelines. We're not here to do your homework for you.
I assume you have 1 row of the array in each line of your input file, and the records (so columns in that row) are separated in some way that you can detect.
What you do is you use that criterion to split up the string you read (it reads a line at a time in my code) and fill the columns of your array with the resulting data.
So in pseudo code:
while no readerror on read line
split line
set columns
increase counter
wend
you should anyway use ifstream instead of fstream for reading...
Omitting all errorchecking, the following will read and echo lines from a textfile:
#include <fstream>
#include <string>
#include <iostream>
#include <iomanip>
int main()
{
ifstream fs;
fs.open("test.txt");
string s;
while (fs >> s) cout << s << endl;
fs.close();
}
of course it's homework.
If it were not it wouldn't be worded as "do this, do that" which is most likely an exact replication of the text of his assignment...
I think you're onto something.
Where is the CTimeCard initialised?
What is it anyway? If it's a reference to something else you're calling a method on an uninitialised object which will indeed cause an access violation.
The real error will be in the InitInstance() method.
hmm, thread shows up as having an answer but none shows...
To continue:
Freely available:
Java : http://java.sun.com
C/C++: both Microsoft and Borland have free compilers. Search for VCToolkitSetup.exe on http://www.microsoft.com or freecommandlinetools.exe on http://www.borland.com
Perl: http://www.perl.org
Python: http://www.python.org
OpenGL: not a language, rather a toolbox. Included with all or most C++ compilers, available for other languages. http://www.opengl.org
Pascal: no free version that I know of for Windows based systems, at least no current one.
(Visual) basic: don't bother.
http://bdn.borland.com/museum/ has old Borland products for free download (free registration required). More for the curious than for serious study, they're not up to current ANSI/ISO standards (or for Pascal Borland's standards, Borland being the main Pascal compiler creator in the world today).
Many Unix/Linux versions come with C/C++ compilers built in as well as Python, Perl, and a lot of other languages.
whatever happened to WordStar? Do they still exist?
WordStar was the preferred choice of the scientific community in the 1980s and early 1990s, afterwards superceded by WordPerfect 5 which had a marvellous equation editor.
LOL. It's not a new browser. It's merely a new shell around IE, a skin if you like.
That's the power of IE, you can incorporate its functionality in nearly any application you like.
Along the lines of this product you have an alternative to IE built right into Windows itself: Windows Explorer. When you type a URL into the input box on top where you see your directory and drive letter it will go to there. It IS in effect IE with some extra functions on the side.
also: asking for private help in a public forum is rude. Help is given so everyone can benefit from it, that means we're not going to send you an answer as an email.
just trying to make people think for themselves Dani... There's way too much "I don't want to think, I just want a canned solution so I won't fail my test" attitude these days.
If those people graduate without writing code they'll become problems for us as colleagues and we'll end up with more work as we'll have to do their work as well leading to unpaid overtime, missed deadlines, etc. etc.
or just click on the Gooooogle adds that show up in this thread for a lot of hot deals in and about Hanoi :)
do you know how to use interpunction?
your ramblings are completely incomprehansible.
DirectX is what's used in most Windows games nowadays, though OpenGL is also an option.
If I were you I'd spend a lot of time learning C++ properly before dabbling in DX coding as DX is a mess (I know, I've looked into it).
It's a mix of C++ and C using a lot of COM components with the typical weird Microsoft naming conventions.
one letter variables can be helpful, for example as loop iterators where they really have no meaning except as a simple counter and have a very limited lifespan (when you use for (int i=0;i<10;i++) everyone knows what i does, when you declare int i asa a global and first use it 100 lines later it get hard to read).
Games aren't written in VBScript. Most of them these days are writting in C++ with a scattering of other languages taking the scraps (Delphi, Java, being the largest of those).
Of the C++ compilers used VC++ has by far the largest market share.
VBScript may be used by some game designers as an internal scripting language for some things but it won't be the core of the game (at most something like scripting the behaviour of NPCs and for that Python is probably more common).
Variable names make a difference in how easy your program is to maintain and how many bugs you'll introduce writing it.
They'll also affect the way your colleagues will treat you, whether you'll get a pizza or a one way trip out the 3rd floor window during the next crunch session :eek:
They won't matter a thing after the compiler is through with it.
This book will suck ur brain out.
Only if it wasn't properly attached to the common sense.
yes, visual studio is all the languages packaged together with some extras.
might be because it's a beta. I use Visual Studio .NET 2002 here and it's pretty fast apart from sometimes taking a while to load a project (which I suspect is my virusscanner holding things up rather than VS itself).
Visual Studio includes not only VC++ but also C#, J# and Visual BASIC.
VBScript is included in MS Office, maybe in Visual Studio as well (it's pretty generic in MS products as a macro language).
Depending on the version of VS you purchase it may also include things like Interdev, Visual Source Safe, MSSQL Server (development license) and other tools.
Check out http://msdn.microsoft.com/vstudio/ for details.
There IS a difference between the C++ compilers in the standard and Pro (included with VS) products. The compiler in VC++ Standard is not an optimising compiler meaning that optimisation options aren't available.
This is no problem for learning and small applications (unless performance critical) but for larger and performance critical applications you will want the optimising compiler from the full VS at least for your final (deployment) build.
Go to the nearest bookstore selling computer books. If they're halfway decent they'll have a shelf of books related to C including tutorials.
Also pick up a copy of the standard work "the C programming language" by Kernighan and Richie
As Dani notices the revenue from each individual ad has plumetted in recent years. This is a global phenomenon that all sites have to deal with.
Many ads that used to bring 10 cents per view now bring only 0.1 cent per clickthrough or worse 1 cent or less per successful transaction resulting from a clickthrough.
As the rate of views to clickthroughs is something like a thousand to one at best and the rate of transactions to clickthroughs is several hundred to one at best you can calculate for yourself what this does to ad revenue.
As to paying for sites. I currently have paid subscriptions to 2 sites, each costing me about $50 a year. In addition I do volunteer work for several more (effectively paying with time I spend to help them so they don't have to hire someone).
There's some more sites I would donate to if only they had a payment mechanism that doesn't rely on PayPal or IMOs.
There's little that can not be done in Java, mainly things very close to the hardware (and with the right hardware you can do even those).
Can you try to have non-animated banners only?
More than a bit distracting (which is the purpose of the animation I know, to the annoyance of the reader ;) ...).
And yes, the banner placement is fine. Far better than some sites I (used to) frequent where there's banners galore down all sides of the page as well as spread all over the text.
Accepting only paypal as a payment service is a big block towards receiving donations (as are the rates which seem steep compared to what sites I donate to charge).
People in many countries can't use paypal at all and personally I don't trust them (there's been too much trouble with their reliability, plus extremely poor service in case of bad transactions) and as the monetary system is all about trust that means I won't use them.
I understand that pp is the easiest system to set up but please consider other options like credit card payments (which don't have to be more expensive than is pp and are a lot more secure).
I've taken up this issue with several other sites: I won't donate to a group that accepts only pp nor will I buy any product where pp is the only payment option.
Cheques and IMOs are also not really an option. Cheques don't exist here and IMOs cost a ton to use. I've sent cash through the mail successfully but you have to know how to mask the package so as to not make it look like cash (plus I've heard that in some areas it's illegal to send or receive cash through the mail).
I made no logical changes in the code.
All I did was reformat what was there, adding some indentation...
OK, done some formatting on that code to see how it looks...
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <conio>
class phoneBook
{
char name[20],phno[6];
public:
void getdata();
void showdata();
char *getname(){ return name; }
char *getphno(){ return phno; }
void update(char *nm,char *telno)
{
strcpy(name,nm);
strcpy(phno,telno);
}
};
void phoneBook :: getdata()
{
cout<<"\nEnter Name : ";
cin>>name;
cout<<"Enter Phone No. : ";
cin>>phno;
}
void phoneBook :: showdata()
{
cout<<"\n";
cout<<setw(15)<<name;
cout<<setw(8)<<phno;
}
int main()
{
phoneBook rec;
fstream file;
file.open("phone.dat", ios::ate | ios::in | ios:ut | ios::binary);
char ch,nm[20],telno[6];
int choice,found=0;
while(1)
{
clrscr();
cout<<"\n*****Phone Book*****\n";
cout<<"1) Add New Record\n";
cout<<"2) Display All Records\n";
cout<<"3) Search Telephone No.\n";
cout<<"4) Search Person Name\n";
cout<<"5) Update Telephone No.\n";
cout<<"6) Exit\n";
cout<<"Choose your choice : ";
cin>>choice;
switch(choice)
{
case 1 : //New Record
rec.getdata();
cin.get(ch);
file.write((char *) &rec, sizeof(rec));
break;
case 2 : //Display All Records
file.seekg(0,ios::beg);
cout<<"\n\nRecords in Phone Book\n";
while(file)
{
file.read((char *) &rec, sizeof(rec));
if(!file.eof())
rec.showdata();
}
file.clear();
getch();
break;
case 3 : //Search Tel. no. when person name is known.
cout<<"\n\nEnter Name : ";
cin>>nm;
file.seekg(0,ios::beg);
found=0;
while(file.read((char *) &rec, sizeof(rec)))
{
if(strcmp(nm,rec.getname())==0)
{
found=1;
rec.showdata();
}
}
file.clear();
if(found==0)
cout<<"\n\n---Record Not found---\n";
getch();
break;
case 4 : //Search name on basis of tel. no
cout<<"\n\nEnter Telephone No : ";
cin>>telno;
file.seekg(0,ios::beg);
found=0;
while(file.read((char *) &rec, sizeof(rec)))
{
if(strcmp(telno,rec.getphno())==0)
{
found=1;
rec.showdata();
}
}
file.clear();
if(found==0)
cout<<"\n\n---Record Not found---\n";
getch();
break;
case 5 : //Update Telephone No.
cout<<"\n\nEnter Name : ";
cin>>nm; …
let them burn once so they never burn again. One bad grade won't hurt anything but his pride but he may learn from it to think for himself.
Not sadistic, just realism.
now why did you alert him to the fact that he shouldn't just submit that code as his assigment?
Don't we want people who're too lazy to do their own work to get burned?