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

>>wanted solution

I want a million dollars too -- will you give it to me ??? Kindly deposit it into my paypal account.

Hint to the solution: use strstr() to find the substring, then subtract two pointers (return value of strstr() and the original pointer)

char str = "Hello World";
strstr( str, "World") - str + strlen("World");

The above will crash if "World" is not contained in str.

Grn Xtrm commented: LOL. Yeah, I'll take some too! +1
dkalita commented: couldn't be better :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) suggest you define macros STDIN and STDOU instead of hardcoding 0 and 1 in the read/write statements

#define STDOUT  1
#define STDIN   0

2) use sizeof operator to get the size of data

write( STDOUT, buf4, strlen(buf4) );
    read( STDIN, myArr[i].gender, sizeof(myArr[i].gender) );
    write( STDOUT, buf5, strlen(buf5) );
    read( STDIN, myArr[i].status, sizeof(myArr[i].status) );

[edit] And what they said above ^^^^ [/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
num3 = (num1 * num2) / 2.0;
cout <<  "Their average is " << num3  << "\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I suppose you could create a batch file that would do it then call it from system().

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

try using more parentheses, like this: cout << "Their average is " << (num3 = (num1 * num2) / 2.0); or splitting it into two separate lines.

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

Post the errors. My guess is that it doesn't like line 10.

lines 15 and 16: The value of revl is 0 (line 12) so the results of those calculations will also be 0.

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

>>I seem to recall I had to include iostream.h to use the CString class. Do I have that right?

No. You need to create an MFC program or a console program that supports MFC. The IDE will generate the files with necessary includes, such as afx.h.

1) There is no relationship between CString and iostream. They are two distinctly different c++ classes, one can be (and usually are) used without the other.

2) CString is part of MFC, so it can't be used without MFC.

Why would you want to use CString in a non-MFC program? There already is an alternative -- #include <string>

Frederick2 commented: Thanks for the input Ancient Dragon! +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 23 and 28: remove those damned semicolons at the end of the lines.

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

>>assuming that codeblocks will add the extention for me.
I just tried it and It didn't -- you need to add that too. Check the filenames in Workspace to see that you do have all the *.cpp files you need.

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

we need SDL_image.h and SDL_ttf.h too because they were not included in the development package I downloaded with SDL-1.2.13

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

Both Fedora 11 and Ubuntu work with all the hardware I have -- HP Officejet 6500 All in one printer, 1.5TB USB HD, HP Pavilion m8530f computer, flat-screen monitor, Logitech wireless keyboard/mouse. The problem I found was lack of support for 65-bit operating systems. Example: Abode does not have 64-bit Flash drivers, so I can't watch films or movies while running *nix; I have to boot with Vista to do that.

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

Did you start out by creating a new project -- Project --> New -->Project, then select the Console Application icon. Then you have to add both main.cpp and process.cpp to the project.

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

zip up the project and attach it. Make sure you delete all compiler-generated files.

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

don't add the '-' until the words are printed out at lines 18 and 19. Then print two words at a time with the '-' between then.

for( int i = 0; i < svect.size(); i += 2 )
    cout << svec[i] << '-' << svec[i+1] << '\n';
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You probably have to tell your compiler where pjsip\include is located. How to do that will depend on the compiler.

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

I have noticed on some boards (e.g. http://www.dreamincode.net/forums/showforum15.htm) that when I post two consecutive posts the forum software will merge them into a single post.

Is something like that possible to do here at DaniWeb ? Of course it would have to be pretty low on the TODO list.

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

I wonder if that's why I was unable to login to Tweeter this evening after work?? They must have reset my password, because I had to request a new one and set my password all over again.

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

you need to post the code you have that shows how you are getting the text from the edit box and how it adds text into the map. Is each map entry a unique character buffer or are you using the same buffer for each entry into the map.

Here is an example that works with standard console c++.

int main()
{
    map<TCHAR*,int> theList;
    TCHAR text1[100] = _TEXT("Hello World");
    TCHAR text2[100] = _TEXT("DaniWeb C++ Forums");
    theList.insert(pair<TCHAR*,int>(text1,1));
    theList.insert(pair<TCHAR*,int>(text2,2));

    map<TCHAR*,int>::iterator it = theList.begin();
    cout << (*it).first << "\n";
    it++;
    cout << (*it).first << "\n";
    
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You probably should have split this into two different threads because both the problems have different solutions. So I'm only going to comment on the first problem.

line 11: This is declaring an unitilized pointer which points to some random location in memory. You have to allocate memory to it before it can be used in a line such as line 13. Its far simpler to declare it as a character array, such as char add[126]; , which will hold up to 125 characters plus string's null terminator.


line 13: The >> operator will not allow you to enter spaces, so if you want a sentence then cin >> add will not work. What you want is cin.getline(add, sizeof(add)); Now you need to declare another pointer so that add is undisturbed.

char *ptr = strtok(add, ","); // split the strig at the comma
cout << "unit num = " << ptr << "\n";
ptr = strtok( NULL, ",");
cout << "street address = " << ptr << "\n";
// etc. etc
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Did you try pointers? insert(pair<TCHAR*,int>(text,1))

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

It doesn't work because calcTotalTime() isn't changing the values of the input parameters.

>>really? it compiles for me and runs hmm...
Yes -- didn't you try to compile it :S

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

>>Can anybody help me with this question??

Yes, start here. Then post the code that YOU have written and ask some questions if you need to. Read in your text book about loops.

#include <iostream>
using namespace std;

int main()
{
    // put your program here

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

put some debug print statements in the program so that you can try to trace what it is doing.

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

g++ -o Taddmain Tadd.cpp Taddmain.cpp

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

Neither Fedora nor Ubuntu work correctly on 64-bit computers; I mean the os itself is ok but they have problems with sound and playing movies. Vista works great right out of the box with no tweaking needed. So my vote is for Windows. Never used a MAC so don't know about it.

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

#include <iostream>

Can't use that in C programs.

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

see cross-post in C forum.

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

>>printf("%s",(char*)ch);

I've told you about that before in another thread. %s says the next argument is a character array, but all you are passing is a single character. What you should use is "%c", then remove that damned typecast.

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

you can not test for EOF when working with binary files because that may be a valid character in the file. What I would do is read/write with blocks of data, using fread() and fwrite()

unsigned char buf[255];
size_t size;
while( (size = fread(buf, 1, sizeof(buf), fp) ) > 0)
    fwrite(buf, 1, size, fpW);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>am i missing something?
Just add a counter, when it reaches 20 then stop the loop. Also, pay attention to the quantities that are displayed because the smallest ones are sorted to the top, not to the bottom. So the first 20 items in that array will be the smallest, not the largest. To fix that you will need to change the sort callback function on line 18 of your original post to use > operator instead of <.

>>damn why cant i use the CODE button
I don't use a button, just add code tags manually

[code]

// put your code here

[/code]

NEW DANIWEB FEATURE Look at the top of the Quick Edit window, next to the other buttons, and you will see [code] button. Just click it and paste your code between the two tags as I showed above.

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

You can not set environment variables like that because they are set only while the system() function is running. As soo as system() returns to your program the new environment variables disappear. Its identical behavior in MS-Windows and *nix operating systems.

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

lines 45 and 46: getline() reads the entire line, then on line 46 you are trying to read just a single word from that line. If you need to split up the line into individual words then either delete line 45 and not use getline() at all, or delete line 46 and use stringstream to split the line.

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

>>to open it, I wasnt notified about any error.

FILE* fp = fopen(("newdb", "r+");
if( fp == NULL)
{
   cout << "Error opening db\n";
}

>>It doesn't really open a new window consisted of my db, does it?
No, that has nothing to do with windows. If you want a new window then you will have to create it yourself. google for win32 api tutorials.

2) I don't know what sqlite.exe is. See this short tutorial I wrote. Beyond that, you should probably join their forums to ask tech questions about sqlite.

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

This should do it

vector<pair<string,int> >::iterator it;

for(it = wordvector.begin(); it != wordvector.end(); it++)
   cout << (*it).first << " = " << (*it).second <<  "\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) check to see if db exists? That would be like checking if any other file exists, e.g. attempt to open it and if open failes then the db does not exist.

2) write a query to get all results, e.g. "SELECT * FROM MyTable" then view the results returned.

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

>>std::list<Operation *> *OPlst;
>>OPlst = new std::list<Operation *>;

Why in the world is this a pointer??? It should be just this: std::list<Operation*> OPlst;

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

Frederick: In the destructor it is not necessary to check for a NULL pointer -- the delete[] operator works correctly when given a null pointer.

In the constructor: suggest you add the const keyword to the parameter, e.g. String::String(const char* pStr) LenStr: Suggest this be an inline function so that the compiler can optimize it better.

lpStr: ditto as above

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

Could you enumerate the reasons why you think so?

It should be quite obvious why. Example I have seen in working production code.

char buf[] = "Hello World";
// This calls strlen() multiple times
for(int i = 0; i < strlen(buf); i++)
{

}

// This calls strlen() only once
int len = strlen(buf);
for()int i = 0; i < len; i++)
{

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

Both are equally good ...

Sorry, Tom, but they are NOT both equally good. That is one reason so many programs are sluggish or slow today because coders are careless about program optimization.

In many cases of calling inline functions, you are right that it may not really matter because the compiler's optimizer will probably toss out the function call and replace it with a variable.

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

AFAIK we were never able to list just the solved threads. The best you can do is list all the threads that you posted in and the ones you started.

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

>>can you check if my program code is right
Didn't you compile and run it to see for yourself?:?:

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

Yup! glad you are finally figuring that out! Never put a function call there which will always return the same value -- its better and faster to store the value in a variable and use that variable in the loop.

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

There is no such function as snprintf()

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

The fopen() statement is the same, except with "w" open flag instead of "r"

use fprintf() to write text lines.

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

Since the path contains spaces you need to enclose them in quotes. And you will need -L flag to point to the directory that contains the libraries -- *.so or *.a.

Personally, I would put them in a different directory that is much shorter and doesn't contain spaces, such as c:\gtk2

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

you have to overload the << operator

class MyClass
{
public:
   friend ofstream& operator<<(const ofstream& out, const MyClass& str);
..
...
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

static class data objects also have to be declared like normal globals.

#include "DivSales.h"
#include <iostream>
using namespace std;

DivSales::totalSales = 0;

void DivSales::addTotal(int a, int b, int c, int d)
{
	cout << "Enter 1st Quarter:" << endl;
	cin >> a;
	cout << "Enter 2nd Quarter:" << endl;
	cin >> b;
	cout << "Enter 3rd Quarter:" << endl;
	cin >> c;
	cout << "Enter 4th Quarter:" << endl;
	cin >> d;

	quartSales[0] = a;
	quartSales[1] = b;
	quartSales[2] = c;
	quartSales[3] = d;
	totalSales = (a+b+c+d);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Dani, I really like what you did with those "<language> Features" on the right side of the screen. That was a greate improvement. Now we have a very easy way to find snippets, tutorials, etc. :*