Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
std::string line;
<snip>
while( getline(infile,line) )
{
   int rank;
   int sales;
   std::string name;
   stringstream str(line);
   str >> rank >> sales;
   getline(str,name);
   cout << rank;
   for(int i = 0; i < sales; i++)
     cout << '*';
   cout << " " << name << '\n';
      
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Please post the first few lines of the csv file so we have something with which to test your program.

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

The file you posted contains three columns -- two numbers and a string. What do the first two columns represent?

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

I found one way to do it, but I'm not very happy with the Find() method because it only passes one parameter to the comparison function (called a Predicate). If you want to find a specific cat I don't know how to do it without using some sort of global variable that contains the cat name. CLI/C++ does not permit String^ to be global. So the Find() method is not very useful in this case.

bool FindCat(MyCat::Cat^ c)
{
    return true;
}

int main(array<System::String ^> ^args)
{
    List<MyCat::Cat^>^ catList = gcnew List<MyCat::Cat^>;
    catList->Add(gcnew MyCat::Cat("one"));
    catList->Add(gcnew MyCat::Cat("two"));
    catList->Add(gcnew MyCat::Cat("three"));
    String^ catname = "two";
    MyCat::Cat^ myLocatedCat = catList->Find(
        gcnew Predicate<MyCat::Cat^>(FindCat) 
    );
    Console::WriteLine(L"Hello World");
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

After the validation you cn convert the string to an integer if you want to.

#include <sstring>
...
<snip>
int n;
stringstream s;
s << number;
s >> n;
cou << n << '\n';

Unless you are instructed to do so there is no reason to put each digit of the string in its own int variable. But you could do that too

int n[5];
for(int i = 0; i < number.length(); i++)
   n[i] = number[i] - '0'; // convert ascii digit to binary
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Apparently the design works -- everyone is talking about it aren't they :) :)

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

I mean something like this:

int main()
{
   std::string number;
   cout << "Enter 5 digits\n";
   cin >> number;
   for(int i = 0; i < number.length(); i++)
   {
     if( !isdigit(number[i]) )
     {
        cout << "You idot!  Numeric digits only!;
        break;
     }
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>string substr(int pos = 0, int n = string::npos)

That's not likely to work. string::npos does NOT mean the end of the string but rather the largest possible value that can be assigned in a size_t variable. See this link for more details.

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

The easoest way to validate that all input only contains digits it to get the input as a string instead of an integer. Then you can easily determine if it contains any non-digit characters without screwing up the entire input stream.

>>while((!isdigit(numbers[k]))
Useless loop because numbers can not hold anything other than digits. And cin will not let you enter anything other than digits in numeric variables.

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

>>take same time as

Not necessarily, depending on how the compiler implements strchr() function. calling strlen() on every loop iteration is very very time consuming and I doubt any compiler will implement strchr() with that. On Intel compatible x86 processors compilers can use a processor instruction to do it.

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

>>if ((int)*ttt[j]==' ')
1. No need for the typecase.
2. loop couters should be int, not char
3. Remove the * from the array declaration
4. Functions must have return types -- default returns is not permissable.
5. Variable k chould be declared as char not int. int is_tic_tac_toe_full(...

void tic_tac_toe_init (char ttt[3][3])
{
    int i,j;
    char k=' ';
    for (i=0;i<3;i++)
    {
        for (j=0; j<3; j++)
            {

            ttt[i][j]= k;
            printf ("%c\n", ttt[i][j]);
        }
    }
}
int is_tic_tac_toe_full (char ttt[3][3])
{
    int i, j, k=0;
    for (i=0;i<3;i++)
    {
        for (j=0; j<3; j++)
        {
            if (ttt[i][j]==' ')
            {
                k++;
            }
        }
    }
    if (k>=1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Homework?

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

Do you realize you just responded to a 2 1/2 year old thread :)

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

Yes it is possible. A segment is determined by the address in ds register. It has nothing to do with align type. AFAIK segments are never closer than 16 bytes (one paragraph), which is the smallest amount of memory that will be returned by memory allocation function (int 21h, function 48h).

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

Start here

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

int main()
{
   // put your program here
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Would (Float)(x) == (float)(double)(x)

Maybe yes, and maybe no. == does not always work with floats and doubles due to the way they are stored in memory. Testing for equality with floats/doubles is always unreliable and risky business.

>>I know 2) is not true, as floating point numbers are not associative
What gave you that idea? The statement is true regardless of the data type of dx and dy.

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

>>void main()
It's int main() -- never void main

>>1. INTEREST, BALANCE and principal become negative
Its very rare that the amount of the final payment will be exactly the same as it was during the life of the loan. So you have to adjust the final payment so that the balance is 0.

The for loop needs to count one month less than num_year*12

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

One way to do it is to use another character array to copy all the characters in s1 that are not in s2.

void trimString()
{
   char s1[] = "hello world";
   char s2[] = "el";
   char s3[255] = {0};
   size_t sz1 = strlen(s1);
   size_t j = 0;
   for(size_t i = 0; i < sz1; i++)
   {
       if( !strchr(s2,s1[i]) )
          s3[j++] = s1[i];
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use libcurl. I have not used itmyself so I can't help you with that, but there are a lot of other members who can.

Also get boost libraries -- specifically this one

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

>> char q;
>> char SENTINEL = q;

The second line does nothing more than assign one char value to another. What's the value of 'q'? Answer: Undetermined because 'q' just contains whatever random value happens to be in the memory at the time.

If you want SENTINEL to represent when to exit the loop then assign it like this char SENTINEL = 'q';

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

1. You are getting repeated entries because you display the word every time if contains one of the letters you entered. Don't do that. Wait until the program has counted the number of letters in the word then, if the count >= 2, display the word and its count.

Problem 2: The only way I know of to resolve that problem is to keep a list of all the words that contains the letters and their associated letter count. The simplest way to do that is to use a vector of structures.

struct wordcnt
{
    string word;
    int count;
    wordcnt() {count = 0;}
};

vector<wordcnt> wordlist;

Now whenever a word is read from the file that contains two or more letters from the input list then add a new item to the vector. After the program is done reading the file you will need to sort the vector using std::sort declared in <algorithm> header file.

// This function is called by std::sort to sort the
// vector first by count and then by word.
bool compare(wordcnt& w1, wordcnt& w2)
{
    int x = w1.count - w2.count;
    if( x == 0 )
    {
        x = w1.word < w2.word;
    }
    return x > 0;
}

...
... <snip>
std::sort(wordlist.begin(), wordlist.end(), compare);

Finally, display the entire list

vector>wordcnt>::iterator it = wordlist.begin();
for( ; it != wordlist.end(); it++)
{
    cout << (*it).word << "\t" << (*it).count << '\n';
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

how do i reboot a hp presario 2003

See start menu button.

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

use <fstream> and associated functions

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

@firstPerson: Nice math lesson, but it doesn't tell us how to extract the digitis without using the % or / operators, or converting to a string, or " without the aid of STL or any other library functions" :) I'd be interested in seeing the solution too -- if there is one.

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

Just follow the code you posted. The algorithm is already there -- just replace < and > ith strcmp()< 0 and strcmp() > 0. If you are not familar with strcmp() then study up on it -- see this for example.

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

After you call EnumWindows() to find the get the window's HWND handle.

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

how can I build a skyscraper? Please tell me instructions and blueprints.

First you have to determine what information you want in the database -- last name, first name, address, city, etc etc. Next step is to design a structure to hold all that information for just one person.

Now, what kind of database do you want? MS-Access, Oracle, Sybase, MS SQL, text file, binary file, Excel file, or something else. Which one you choose will determine how you have to write the program to store the information.

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

That's right. Maybe this will help you.

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

replace string names[100] with char names[100][40]; replace string searchname with char searchname[40]; void binarySearch(char array[100][], int len, char* searchItem) use strcmp() instea of std::string's overloaded < and > operators

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

call win32 api function EnumWindows() to see if FF is running.

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

And how to you expect a Dialog box to run on a browser (Firefox, IE, or anything else)? AFAIK it can't. MFC programs run directly on a PC computer that is running MS-Windows operating system. FF also runs on MS-Windows but has to get all its information from a web server across the internet.

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

>>And in school we used VC++ but I don't have it at home

Why not? The express version is free for the asking (downloading). Would you build an engine for a 50 year-old car and expect it to work on a 2010 model?

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

Confusion -- how are you making a browser window with C++ and MFC??? I know MFC has an html control, but that doesn't use a browser.

In html code I think it can check the browser type and act accordingly. But you'd have to ask that question in one of the other forums here, not in c++.

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

>>cannot covert from const char [2] to wchar_t
Hummm. If you are compiling the program for UNICODE then why aren't you getting similar errors on all the other lines in your program (such as line 5)?

You could have avoided that problem altogether had you used ifstream and getline() instead of C's FILE and associated C functions.

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

Firefox is a web browser, not an application window. You are going to have to explain a lot better what you are attempting to do.

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

It would be a lot easier to use std::vector<std::string> instead of that string array, then call std::find instead of your binary search algorithm

Post a few lines from the data file you are using.

EarendurRingern commented: thx :) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I finally got this worked out (I'm newbe to Windows Forms).

1. Create Form2 with checkedListBox, or you may already have it on another form. Add this code in Form2.cpp. The form designer doesn't like having loops in the *.h file so I had to put the code in *.cpp file.

#include "StdAfx.h"
#include "Form2.h"

using namespace System::IO;
namespace MyApplication { // Change this to the name of the application
    void Form2::GetMyDrives()
    {
            array<DriveInfo^>^ allDrives = DriveInfo::GetDrives();
            for each(DriveInfo^ d in allDrives)
            {
                this->checkedListBox1->Items->Add(d->Name);
            }
    }
};

2. Call the above function from the InitializeComponent() method in Form2.h, after other initialization for checkListBox1 component.

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

I down voted you just because of the crazy/childish title you gave this thead. Otherwise what can I say except that the code you posted is horribly formatted.

On positive note -- you used code tags correctly on your very first post :) I would probably have up reped you for that but wont because of that horrid title.

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

>>i dont know how to improve my programming skills

Practice, practice, practice. The only way to improve it is to study, read other people's code (program maintenance) and coding your own programs. With time your coding skills will eventuall improve. A bachelor's degree is not the end of your learning, but only the beginning.

Apply and get yourself an entry-level programming job. Employers won't expect you to have the skills of someone with several year' experience. Just show them you have basic programming skills and have the potential to perform well for them and you will be ok. Then learn as much as possible while on the job -- and don't be afraid of constructive criticism. Many programmers become very offended when someone tries to critique the code they have written. Accept their criticism with positive attitude so that you can learn from experienced people.

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

Suggest you read this explaintion and example I don't think you need all that recursion.

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

You have a little cleanup to do on existing code. Make it work corectly before continuing.


>>cdStruct *start = new cdStruct; // first element will NOT handle any info
why?? That's just a waste of memory. Set start = NULL and pass it to addEntry() by reference instead of by value. That's the way linked lists are usually maintained. void addEntry(cdStruct** start) line 15: The output stream is already opened by the calling function -- saveStructList(). So all you have to do is pass save() a reference to the stream object void save(cdStruct *ptr, ofstream& dataFile); then delete lines 17 and 23.


line 162: Don't you care if you enter the same cd title multiple times, creating multiple nodes for the same cd??

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

don't use a loop. See this link

mov ecx,4096
mov edi,offset ???
xor eax,eax ; set eax = 0
rep stosb

You can inprove the performance of that a tiny bit by using stosd and storing in ecx the count of dwords instead of bytes

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

That's nice -- no one here is going to stop you.

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

MS-Windows programs can use GetSystemTime()

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

At the bottom of the thread you started you will see "Has this thread been answered?". The text under that contains a link to mark your thread solved.

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

Then do something like this

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using std::cout;
using std::string;
using std::vector;
using std::sort;

int compare(vector<string>& s1, vector<string>& s2)
{
    return s1[0] < s2[0];
}

int main()
{
    vector<vector<string>> table;
    sort(table.begin(), table.end(), compare);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

So you have vector<vector<string>> table; ? Do you want to sort the rows of the table, or sort the strings in each of the rows?

If the first row contains "b" and "a" the result should be "a" and "b"?
That will simplify the sort

vector<vector<string>>::iterator tbit;
vector<string>::iterator it;

for(tbit = table.begin(); tbit != table.end(); tbit++)
{
    vector<string>& row = *tbit;
    std::sort(row.begin(),row.end(), row.begin());
}

}