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

lpReturnedString is a buffer in which the function will store the string that you want. You have to declare the buffer, and the function will fill it in.

Example: You have to replace "SectionName" and "KeyName" with appropriate values that are in your *.ini file. Read the Remarks section for that function for more information and examples.

char buf[255];
DWORD nCharacters = GetPrivateProfileString("SectionName", "KeyName", NULL, buf, sizeof(buf), "c:\\mydir\\myfile.ini");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I spent most of the day working -- at WalMart. But I did have a couple flags flying outside my house.

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

compile that program for debug then use your compiler's debugger to step through the program one line at a time until you find out where the error occurs. One of the most common errors to look for is buffer overruns and using uninitialized variables.

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

You can use the registry functions for *.ini files. See this link, then scroll down the page until you find GetPrivateProfileInt() and etc.

Or you could just write your own functions to read/write/update the *.ini file. Since *ini files are just text files you will have to rewrite the entire file in order to change anything. If you have a lot of changes to be made at one time then it will be a lot faster to do it yourself rather than use the win32 api registry functions.

Rajesh R Subram commented: Perfect answer. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First define the structure you want to store in the file (database). Then begin writing the code to prompt for the information needed to fill in one structure member. When that is filled in save it to the file. Myself, I would use binary files because they are easier to write, read and search but the file format may or may not be specified in your program specifications.

Don't get overwhelmed by the complexity of the program. Break it down into small chunks, code and test one part at a time and pretty soon you will have the whole thing completed.

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

>> searchFor = "*my\*day.*";

That will not compile -- if you want a \ in the string then you have to put two of them, so the code should be searchFor = "*my\\*day.*"; Otherwise the program appears to work ok for the tests I made. Now I think you should improve the program by allowing ? as a wild card that matches just a single character.

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

use global variables. You will have to synchronize access to the variables so that one thread doesn't try to read it while another thread is writing to it.

If you are writing a MS-Windows GUI program then you might be able to call SendThreadMessage().

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

Redraw them in the same color as the background. Or I suppose you could save a bitmap of the entire screen before you start drawing the rectangles and redraw the screen with that bipmap when you want to clear it.

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

What have YOU done to solve the problem? You will need to post the code you have written and ask specific questions about what you do not understand.

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

Well, that doesn't work any more. See this post in which I used that code tag

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

an instance of an object is created when a variable is declared. Declaration of a symbolic name just defines a name that can be used in a program.

int muthu1208; // an instance of an object

#define MUTHU 25 // definition of a symbolic name
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Instead of creating an instance for each city you can just create an array of those structures. for example struct Cyprus cities[4]; How to populate the array may depend on the instructions your professor gave you. My guess is that your program should read the data from a text file, buy that may be 100% wrong.

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

what operating system?

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

How can I use code tags that do not produce line numbers? I used to use quote tags, but that is just almost unusable now since the quoted text is hidden. So to preserve the spacing I use code tags, but I don't like the line numbers.

Also, where's the FAQ?

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

You have already almost written it yourself. Groups are done on queries, not updates.

UPDATE table 
SET test4=1
WHERE (test1=1 and test2=1 and test3=2) OR
      (test1=1 and test2=2 and test3=3) OR
      (test1=1 and test2=3 and test3=0) OR
      (test1=1 and test2=4 and test3=1)
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

call win32 api function SetFocus()

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

There are several ways to do it but the oldest and most widely used is ODBC. ggogle for "ODBC tutorials" and you will find out how to do it. It's a lot more complex than in VB, so be prepared for a lot of coding and trials. You might find some c++ classes that will help.

If you want to use MySQL database then you can use MySQL++ classes and libraries.

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

>>Anyway, once you click into the post itself the views are then shown.

Where?? I don't see it in this thread.

Oh nevermind, I found it.

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

you have the val declared twice -- once on line 1 and again on line 3. You can not use the same variable name twice like that.

line 4: you have to call strcpy() to do it: strcpy(var[0],"ANS"); The = assignment operator will not work on character arrays.

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

you have a couple of choices
(1) call fgets() to read each line into memory then search the line for spaces

(2) call fgetc() to read the file one character at a time then check for spaces.

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

>>AD- sort( ) can be called with just the start and end iterators, I assume it makes use of the < operator if no comparison function is provided.

Isn't that what I just said??? But it only works on POD and std::string. most everything else will require the third parameter.

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

We are not here to write your program for you, but we will help you if you show some effort, such as post the code you have already written.

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

Its simple to create yourself. call win32 api function SetTimer() and have it called every 1 second. Inside the event function that you have to pass to SetTimer() do whatever you want to display the time.

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

Where is the *.cpp file that contains main()? Check your project files to make sure one of the *.cpp files contains that function. You said you created an empty project -- my guess is that you forgot to add main()

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

There is a third parameter to std::sort() which is the name of a comparison function that you will write. That is not necessary if you have a vector of standard data types, such as int, double and std::string. Anything more complex such as a c++ class that you created will require the comparison function. See the example program at this link.

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

add #include <windows.h> before mmsystem.h

you may need to turn off UNICODE -- select menu item Projects --> Properties (the last menu item), expand the Configuration Properties tab, select General, then on the right side of the screen, third item from the bottom, change Character Set option to Not Set.

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

Nope -- set inserts the new data in sorted order. Using the program below and the file data in the original post the results are this:

189657          3
319330767               1
371336959               2
449127604               1
808635064               2
Press any key to continue . . .

IMHO a <MAP> would be better than <SET> because I had to typecast out the const in order to update the quantity field of MyData structure that is already in the set. I don't like doing that.

#include <iterator>
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <set>
using namespace std;



struct MyData{
   string part;
   string a;
   string b;
   int quantity;
};


bool operator<(const MyData& lhs, const MyData& rhs)
{
    std::string lhsa, rhsa;
    lhsa = lhs.part + lhs.a + lhs.b;
    rhsa = rhs.part + rhs.a + rhs.b;

    return (lhsa < rhsa);
}
bool operator==(const MyData& lhs, const MyData& rhs)
{
    if( lhs.a == rhs.a && lhs.b == rhs.b)
        return true;
    return false; 
}




void display(std::set<MyData>& fileData)
{
   std::set<MyData>::iterator it = fileData.begin();
   for(; it != fileData.end(); it++)
   {
       cout << it->part << "\t\t" << it->quantity << '\n';

   }
}

int main()
{
    std::string line;
 std::set<MyData> fileData;
 std::ifstream fileReader( "text.txt" );
 if( !fileReader.is_open())
 {
     cout << "Open failed\n";
     return 1;
 }
 while( getline(fileReader,line) )
 {
     MyData d;
     std::string c;
     stringstream str(line);
     getline(str,d.part, ',');
     getline(str,d.a, ',');
     getline(str,d.b, ',');
     getline(str,c, ',');
     if( c == "REF" )
         c = "999";
     d.quantity = atol(c.c_str());
     std::set<MyData>::iterator it = fileData.find(d);
     if( it == fileData.end())
         fileData.insert(d);
     else
     { …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

std::set sorts the data, which is not what the op wants. The order of the data within the container needs to be preserved.

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

I can't even get Turbo C to install on 64-bit Windows 7, let alone try to compile anything with it. There will come a day when India's universities will be forced to upgrade their school's compilers and teaching. They are putting their students at a huge disadvantage by teaching with such old tools.

jonsca commented: N/A +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is one way to do it. I changed stuff to vector<string>

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <fstream>
using namespace std;



class Foo
{
public:
   string part;
   string a;
   string b;
   int quantity;
};



int main()
{
   string line;

   ifstream read ( "bom.csv" );

   vector <string> stuff;


   while ( getline ( read, line, '\n' ) )
   {

      vector <string>chunks;
      Foo test;
      string token;
      istringstream iss ( line );

      /*split the line up using a comma as a delimiter*/
      while ( getline ( iss, token, ',' ) )
      {
         chunks.push_back ( token );
      }

      test.part = chunks[0];
      test.a = chunks[1];
      test.b = chunks[2];

      /*check for REF case
        Sometimes the file doesn't contain valid quantities
        If it doesn't it will alway be REF
        Change this to an arbitrary 999*/

      if (chunks[3] == "REF")
      {
         chunks[3] = "999";
      }
      vector<string>::iterator it = stuff.begin();
      size_t pos1 = line.find_last_of(',');
      string t = line.substr(0,pos1);
      bool found = false;
      for(; it != stuff.end(); it++)
      {
          size_t pos2 = it->find_last_of(',');
          if( it->substr(0, pos2) == t)
          {
              int n1 = atol(chunks[3]);
              int n2 = atol(it->substr(pos2+1).c_str());
              stringstream str;
              str << t << ',' << n1+n2;
              *it = str.str();
              found = true;
              break;
          }
      }
      if( found == false)
        stuff.push_back ( line );
   }

   /*now begin procedure to remove duplicate lines and total quantities*/

   read.close();
   cin.get();

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

As I mentioned before, don't add a new string to the vector unless the vector does not already contain the string. Instead of adding them just combine them. That should be done before line 64. And if you look at the code I posted you don't need that chunks vector.

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

I'm really surprised that you are unable to do that simple program yourself. Here it is compiled and tested. Now all you have to do is finish it with reading from the file into the vector and searching the vector for the string.

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;


int main()
{
vector<string> arry;
arry.push_back("371336959,-New DDM Part-,Y,1");
string newstring = "371336959,-New DDM Part-,Y,1";
int i = 0;
string& s = arry[i]; // duplicate string;
// extract value from the end of the string in the vector
size_t pos = s.find_last_of(',');
int n1 = atol(s.substr(pos+1).c_str());
s = s.substr(0,pos);

// extract value from the end of the string read from the file
pos = newstring.find_last_of(',');
int n2 = atol(newstring.substr(pos+1).c_str());
// add the two values and put back into the vector
stringstream str;
str << s << ',' << n1 + n2;
s = str.str();
cout << arry[i] << '\n';
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I require complete and tested code snippets please!

Thank you.

Are you kidding??? You've been around just as long as I have and you can do that yourself. Besides, I don't have time to do it -- I'm playing Tourchlight game :)

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

Yes I suppose map could be made to work, so would a few other container classes.

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

1. Read the lines into a vector of strings
2. When a line is read, search the vector to see if the line already exists. If it does then just add the quantity to the string that was found. If not then add the new string to the end of the vector
To do that you will have to extract the quantity from the vector string, convert it to a number, do the same with the new string, add them together, then put it back into the vector

Warning: Not compiled or tested. Some people will most likely object to my use of atol(), so substitute anything you wish.

vector<string> arry;
string newstring = "<whatever>";
string& s = arry[i]; // duplicate string;
// extract value from the end of the string in the vector
size_t pos = s.find_last_of(',');
int n1 = atol(s.substr(pos+1);
s = s.substr(0,pos);

// extract value from the end of the string read from the file
pos = newstring.find_last_of(',');
int n2 = atol(newstring.substr(pos+1);
// add the two values and put back into the vector
stringstream str(s);
str << n1 + n2;
s = str.str();

3. Rewrite the file if necessary using the contents of the vector

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

line 13: That loop can be written better to avoid the last line problem. The default behavior of getline is to read until either 80 characters have been read of '\n' is reached, so there is no need to specify a third parameter to the function.

while( in.getline(str[i], 80) ) 
{
   ++i;
}

line 21: variable i has already been declared on line 12 so there is no reason to declare another variable with the same name on this line. Reuse variables whenever possible.

line 23: you need to add '\n' to the end of the string so that they all don't run together.

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

Does that problem happen in other programs too? Such as Notepad ?

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

You will want to include <fstream> and use ifstream's getline() function.

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

You need to post that structure

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

You are going to have to explain what you want a whole lot more. Do an interface to or for what???

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

You can combine lines 10, 11 and 12 to use just one fseek() fseek(source, -10, SEEK_END); That will set the pointer 10 bytes from the end of the file.

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

I just now uninstalled Google Crome and Goodle Toolbar for IE and now the translations don't appear.

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

Oh nevermind. I just went to another web site and it has the same behavior. So it must be IE8.

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

I just discovered that when I hover my cursor over a word a popup window shows the word in several languages. At least that's what I think its doing. Is that DaniWeb doing that or something else? I never noticed that before. I'm beginning to think that maybe its IE8 that is doing it.

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

redeclare values as unsigned char instead of int. Then your program will most likely display the data the same as your hex editor did.

You did not post the code you tried to get the last 100 bytes.

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

What happened to the link for the Newsletter?

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

You are using Trim() incorrectly. None of the Trim overloads take a CString parameter. Nor should the parameter be an array of strings -- only one string that contains the characters you want it to use for trimming. See this example for how to use Trim() correctly.

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

I've already told you that you have to surround string literals with the _T macro CString symb[]= {_T("{{")}; . The reason you have to do that is because you are compiling your program for UNICODE, so all strings both literals and non-literals must be UNICODE.

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

why are you using character arrays instead of integers?

why are you using C's gets() function instead of c++ cin?

If you really really want to use character arrays then you need to make them larger -- you have to account for the string's NULL terminating character. With integers you don't have to worry about that.

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

fread() is normally used to read binary files -- the OP asked about text files. Text files could be read with fread() but it would be somewhat more difficult than using the functions that were designed specifically for text files.