>Narue its a part of utility.h in VS2008 and in Utility.h and xstring on VS2005.
That's nice. And your point is?
kartouss commented: Very Helpful +1
darklich13 commented: Thanks for the help again!! +1
>Narue its a part of utility.h in VS2008 and in Utility.h and xstring on VS2005.
That's nice. And your point is?
When you say "strings of integers", what do you mean exactly?
>is there a built in function to deal with numbers similar to how the swap member function
Yes, include <algorithm> and you can use the std::swap template function as AD has shown.
>so how do i make PI a standard name on my compiler?
Join the standardization committee and convince them to add it.
>It doesn't seem to work with PI or M_PI if i include math.h and/or cmath.h
Right, so look at my first reply and define it yourself.
>happy now
I'm always happy. It comes from confidence in being right and having a thick skin. ;) I am curious though, why did you choose that particular solution over something like this:
#include <iostream>
#include <string>
int main()
{
std::string text = "hello world";
std::string save;
for ( std::string::size_type i = 0; i < text.size(); i++ ) {
if ( save.find ( text[i] ) == std::string::npos )
save += text[i];
}
std::cout<< save <<'\n';
}
Interesting solution. I have one nit though (actually I have several, but there's only one I would call an error):
>if ((text.find_last_of(text, poss-1) == EOF) ){
find_last_of returns string::npos if it doesn't find a match. EOF isn't required to have the same value as string::npos.
>In the initializer, could I just set the two Dates equal to each other?
Without seeing the class definition for Date, I can't say for sure, but I can imagine how it's implemented and be fairly confident that you can do that and it'll work.
>dep(1,1,2000);
>ret(1,1,2000);
This is assuming that your Date class overloads the function call operator and allows three arguments. I'm guessing you don't have that particular overload, in which case what you were trying to do (initialize dep and ret to new instances of the Date class using a three parameter constructor) uses this syntax:
dep = Date(1,1,2000);
ret = Date(1,1,2000);
Likewise further down:
dep = Date(d1, m1, y1);
ret = Date(d2, m2, y2);
ivailosp, that only removes consecutive duplicates. You failed to handle the specific case that I asked about, where "slowly" becomes "slowy".
>what is #include<set.h>??
It's a standard header for the set class (but note that it's <set>, not <set.h>). The set class is basically a data structure that allows you to store and quickly search for items.
Store the characters you've found in a suitable data structure and check the data structure with each new character. If it was seen before, don't do anything, otherwise add it to the data structure and print it. Here's an example using the standard set class:
#include <iostream>
#include <set>
int main()
{
std::set<char> used;
char ch;
while ( std::cin.get ( ch ) ) {
if ( used.find ( ch ) == used.end() ) {
used.insert ( ch );
std::cout.put ( ch );
}
}
}
>Can anyone give me a simple idea how to remove the duplicated letters in a text
Can you be more specific? Should the two L's be removed in "SLOWLY"? If so, which L should be removed? Are the characters to be ordered in any special way? All of these play a part in figuring out your solution.
>M_PI used to be in "math.h". And it's still there.
Only on your compiler. M_PI isn't a standard name.
>What is standard practice?
Most people just define their own as needed:
const double PI = 3.141592;
#define _WIN32_WINNT 0x0502
#include <stdio.h>
#include <windows.h>
int main ( void )
{
HWND console = GetConsoleWindow();
HMENU menu = GetSystemMenu ( console, FALSE );
if ( DeleteMenu ( menu, SC_CLOSE, MF_BYCOMMAND ) )
puts ( "Can't close with the X button" );
else
puts ( "Unable to remove X button" );
return 0;
}
>C seems to be too much sensitive and dependent
>on how you declare variables and functions.
Yep, it's a very finicky language.
>is there a standard cooky cutter approach that works (most) every time ?
Ideally you would put your declarations in a separate header file and definitions in a separate implementation file that corresponds to the header file.
Traicey, that's all well and good, if the OP's compiler supports the string class, which it may not as shown by the use of the pre-standard iostream.h header.
>1. what syntax should i use to insert character that allows 'space'?
cin.getline:
cin.getline ( emp->name, 50 );
>2. is there a syntax that can 'search' name within a list,,, what is it?
It's called a loop:
node *it = strtPtr;
while ( it != 0 ) {
if ( strcmp ( it->name, key ) == 0 )
break;
it = it->nxt;
}
if ( it != 0 )
cout<<"Found '"<< it->name <<"'\n";
And if I may be so bold, is there a shortage of vowels on your system? nxt and strtPtr are exceptionally annoying to type and read.
>me too sensitive!! ... it isn't my thread in the first place.
So you go around playing net nanny on other people's threads? ;)
>it may be my first post on this site, but it isn't the first in my life.
Then you know that talk is cheap. I know nothing about you, so you mean nothing to me.
>it seems we went off topic.
It happens. Often the off-topic topics are more interesting and/or informative than the on-topic topics. Sometimes it's an entertaining pseudo flame war, sometimes it's a technical tangent, and sometimes it's a highly advanced debate between gurus. Just go with the flow and you'll have more fun. :)
First you need to decide if you want to use parameters to move s around, or access it globally. Right now you're mixing the two together and as a result you have way too many variables named s. This uses parameters rather than the global variable:
#include <stdio.h>
void cSend_Byte ( unsigned char );
void cGet_Byte ( void );
void cDispMsg ( const char * );
char s[] = "It is working";
/*
JSW (2008-4-1): Added this for debugging without an emulator
*/
static unsigned char SBUF = 0;
void main ( void )
{
unsigned char mybyte;
do
{
cGet_Byte();
mybyte = SBUF;
cSend_Byte ( mybyte );
cSend_Byte ( mybyte + 1 );
cSend_Byte ( 'Y' );
mybyte = 'V';
cSend_Byte ( mybyte );
cDispMsg ( s );
} while ( 1 );
}
void cDispMsg ( const char *s )
{
int i;
for ( i = 0; s[i] !='\0'; i++ )
cSend_Byte ( s[i] );
cSend_Byte ( '\n' );
return;
}
void cSend_Byte ( unsigned char x )
{
putchar ( x );
}
void cGet_Byte ( void )
{
SBUF = (unsigned char)getchar();
}
And this uses the global directly:
#include <stdio.h>
void cSend_Byte ( unsigned char );
void cGet_Byte ( void );
void cDispMsg ( void );
char s[] = "It is working";
/*
JSW (2008-4-1): Added this for debugging without an emulator
*/
static unsigned char SBUF = 0;
void main ( void )
{
unsigned char mybyte;
do
{
cGet_Byte();
mybyte …
>why are you so upset Narue !!?
I'm not, you're just too sensitive.
>simple ask it was no need to be so mean.
To be perfectly frank, you're in no position to lecture me on your first post.
>[snip description of the solution]
I'm curious why you chose to wait three days and then post essentially the same thing someone else did earlier in the thread.
The compiler doesn't know where to look for total, so it looks for local variables and then global variables. If you want to access the static member, you have to qualify it with the class it's declared in:
item::total += a.itemprice;
Alternatively you can use the object to get to it as well:
a.total += a.itemprice;
More details please. What compiler and OS and is this a GUI program or command line?
>#define pi 3.14159265;
Lose the semicolon. The preprocessor is doing exactly what you tell it and replacing all occurrences of "pi" with "3.14159265;".
>save values to a file on program exit and read on program start
Coupled with encryption and a good tampering check, I'd prefer this one.
>save values in the registry
Which adds a whole new layer of complexity to your application. Best to avoid the registry.
>save values in the program *.exe file
Maybe I'm not up on the latest tricks, but I don't recall ever hearing about this one. It sounds like a good way to corrupt your executable if you aren't careful. ;)
You're all set then. Follow the link I gave in my previous post for details.
There's no portable way to do this. What compiler and operating system are you using? In anticipation of you being on Windows, you can use SetConsoleTextAttribute to give your text color.
>Can u give me some advice to do it ?
I can give you some advice, but you're not going to like it. My advice is to take a step back and work on simpler things, because you're trying to solve problems and write programs that are too far beyond you right now.
All you need to do is keep a count of rows and a running sum of the values. You pretty much had it:
while (fgets(buf, 80, stocks) != NULL && !feof(stocks)) {
sscanf(buf, "%d %d", &stock.x, &stock.y);
printf("n1 = %d n2 = %d\n", stock.x, stock.y);
total += stock.y;
++numberofrecords;
}
>What are the following data types are and the storage requirements of each?
This is something you can find in any C reference. So why are you even asking the question?
char is a byte, the size is 1.
unsigned char is a byte guaranteed never to have a negative value, the size is 1.
int is a signed integer, the size depends on your compiler
long is a signed long integer, the size depends on your compiler.
float is a single precision floating-point type, the size depends on your compiler.
double is a double precision floating-point type, the size depends on your compiler.
It looks like you've nailed down the problem, judging by the extra std::cin.get() calls, but putting them after a return statement means they won't get executed. For example, try swapping this pattern:
return 0;
std::cin.get();
To get this one:
std::cin.get();
return 0;
>To help somebody, in my mind, does not require beginning with rudeness.
Let's see:
>found this is going to be a lot more work then originally expected
What did you expect? I hear this a lot. "It wasn't what I expected!" I get the feeling that people have some pretty messed up expectations when it comes to learning something new.
I challenge you to find someone who thinks this is rude, or an attack, or anything that deserves the reply you gave:
And by the way, since you are never faced with something uinexpected when learing something new, please forgive for not being perfect. I've got a feeling you think that YOU are.
>I consider help being a kind suggestion, answer or
>even politing pointing out of an error in the question itself.
Yet you didn't hesitate to attack me personally while disregarding my kind suggestion:
>and have become only able to use a GUI
Why don't you start with a GUI in Linux then? There's less culture shock that way.
I highly recommend you adjust your attitude. That's a "kind suggestion" from one of your peers.
>I already know how to use GUI.
You know how to use the Windows GUI. Just because it's point and click doesn't mean you can transfer that knowledge to any old OS. Hell, people who were experts with Windows XP have tended to get caught short when moving to Vista, and they're both Windows operating systems.
>If I want to learn linux, Would it not be most benificaial
>to learn what makes it different from windows?
There's that wacky expectations thing again. For some strange reason you think that just because you're using a graphical interface, it's "just like Windows" or that you have to use the command line to understand the system. :icon_rolleyes:
>And by the way, since you are never faced with something
>uinexpected when learing something new, please forgive for
>not being perfect. I've got a feeling you think that YOU are.
With that kind of attitude, nobody will want to help you. Stop being a whiney ass and be grateful that someone more experienced is offering advice. Rest assured, I won't waste my time with you in the future. I don't take kindly to being slapped in the face after trying to help.
>found this is going to be a lot more work then originally expected
What did you expect? I hear this a lot. "It wasn't what I expected!" I get the feeling that people have some pretty messed up expectations when it comes to learning something new.
>and have become only able to use a GUI
Why don't you start with a GUI in Linux then? There's less culture shock that way.
Random access is for when you can't predict the access pattern or you can't deterministically work out a pattern to organize your data for sequential access. Sequential access is for when you don't care about the order of records, can predict the access pattern or organize your data to fit a sequential pattern, or the access medium doesn't support random access.
Here's a hint, people. Use a fixed width font to set up spacing for your output. The post editor doesn't use a fixed width font, so open up Notepad or something equivalent and get your example looking right before you post it. Otherwise you'll end up with too many or too few spaces in the code display because you got it to "look right" with a proportional font.
The filename parameter has to be a C-style string:
ifstream myfile1 (path1.c_str(), ios::binary);
ofstream myfile3 (path2.c_str(), ios::binary);
>is it bad to ask?????
It's bad to ask a question that amounts to "Please do my work for me".
>share your ideas......what do you think.......
I think you're not going to get anyone to tell you how to do this. It's your assignment after all. Start by figuring out how to read an expression from the input stream. You need to be able to build an integer from multiple consecutive digits and recognize operators. Once you can do that it's a simple matter of using the stack to evaluate the expression using polish notation: pop an operator, pop the operands, do the operation, push the result.
If you define a member function for a template class outside of the class definition, you need to recreate the template parameters:
template <typename T>
myVector<T>::myVector()
{
size = 0;
capacity = 10;
data = new T [capacity];
}
template <typename T>
myVector<T>::~myVector()
{
delete [] data;
}
>Always I have favored pointer notation when dealing with string pointers
If you're just using increment and decrement, there's no problem. But if you're already bringing an offset into the mix, there's not really a good reason to avoid the simpler and better understood syntax.
>Can't help but draw a parallel thought of six plus feet men making
>hulk poses for just placing a ball inside an over-sized metal ring.
It's almost like that, actually. ;)
>Is it really that much complex from array[count] that it would warrant wondering?
Yes. Pointer notation for subscripting is unconventional enough to raise red flags. When I see this I wonder if it's a requirement for a homework assignment or if the author is trying to look smarter by using "tougher" looking code. If it's the former I'll write it off as more classroom silliness. If it's the latter, I'll need to be on the lookout for macho code.
Either way, pointer notation is more complicated (if only a little), harder to read (if only a little), causes readers to question the code, and doesn't describe the author's intentions very well.
>Doesn't the compiler default to substitute array notation for pointer notation?
Array notation is syntactic sugar for pointer notation, yes.
>why is there no null character needed?
Dumb luck. The next byte after your array just happens to have the value 0.
>*(array + count) = ch ;
Just out of curiosity, why add the unnecessary complexity of pointer notation here?
>Old? What does that make ForTran???
Older. But old isn't the only measure of a universal language. JOSS is old, but I wouldn't say it's universal by any measure. ;)
>what makes C a universal language
C is old, ubiquitous, well understood, and many modern languages derive syntax and semantics from it.
>The List class contains all the linked list information
This sounds like ListNode is a nested class. Most likely the problem is you're not properly qualifying the type:
List::ListNode cur = new List::ListNode;
cur = head;
cur = cur->next;
You can specify one or more forums from the advanced forum search. Is that what you meant?
>Compile and run it, then do it again with the line //in(buffer,b); uncommented.
It breaks inside if the in function on this line:
current[x]=b[i+x];
And it does this because strlen(a)-strlen(b) in your outer loop condition results in a negative number, yet you increment i from 0.
IIRC, there's a SelectionChangeCommitted event in the ComboBox class. Subscribe to that event and run your code inside the event handler.
while (!inStream.eof()) {
L1.append(temp);
inStream >> temp;
}
You append temp before ever reading anything. That's one of two good reasons not to use eof() as a loop condition. The other reason is that you can get an off-by-one error and process the last item in the file twice. This is shorter and works better:
while ( inStream>> temp )
L1.append ( temp );
KeyPress, KeyUp, and KeyDown are events. You have to set up handlers and subscribe to the event before you can use them. Here's some documentation.