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

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

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

He forgot to make array a pointer int* array = new int[size];

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

I reviewed your two thread and see that you have not answered people's questions. We are not mind readers, not is anyone here clairvoyant. Would you go to an automobile repair shop and tell the mechanic "My car is broke. Fix it please.". Of course not -- you have to tell the mechanic what you think is wrong with it.

We at DaniWeb humbly appologize to you for being unable to read your mind or see your computer's monitor.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
const int SomeSize = 5;
const int SomeOtherSize = 5;
class ClassName
{
};

typedef ClassName SomeName[SomeSize][SomeOtherSize];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you created the project as a DLL project then the configuration type will already be selected for you. You don't really have to do that step. At that point, just hit the Build Solution option

If you don't see a Build menu option -- located just to the right of Project menu -- then you need to change another setting. Select Tools --> Settings --> Expert Settings.

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

Coding anything in c++ is going to be more complicated than in other languages. c or c++ is not necessarily the best language for doing some things.

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

You use normal win32 api functions to do that. Read this

Open the com port with CreateFile. Scroll down the page to "Communications Resources" for more information. And an example c++ program.

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

I didn't get any warnings or errors when I compiled that code with vc++ 2010 Express. Check your code very carefully -- there might be an extraneous character somewhere.

AFAIK that compiler should work ok on XP.

tagazin commented: thanks Ancient Dragon! :) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Probably something like this (untested) code

#include <fstream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;


int main()
{
    std::vector<std::string>  elementVector;
    std::ifstream in("filename.dat");
    std::string line;
    while( std::getline(in, line) )
    {
        if( line == "<et>" )
        {
            std::getline(in,line);
            stringstream st;
            st << line;
            std::string word;
            while( std::getline(st,word,'\'' ))
            {
                size_t pos = word.find('\'');
                if( pos != string::npos )
                    word.erase(pos,1);
                elementVector.push_back(word);
            }

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

Here is one solution, the same as used by many win32 api functions because it avoids the problems of allocating memory in DLLs.

void __stdcall date(char* dateStr, size_t size)
// dateStr is allocated by calling function
// size is the number of bytes allocted to dateStr
	
{
		 
    _strdate_s( dateStr, size); // fills char array with date
}

Or if you want the function to return something

char* __stdcall date(char* dateStr, size_t size)
// dateStr is allocated by calling function
// size is the number of bytes allocted to dateStr
	
{
		 
    _strdate_s( dateStr, size); // fills char array with date
    return dateStr;
}

Example calling function

int main()
{
   char dateStr[50];
   date(dateStr, sizeof(dateStr));
   cout << dateStr << '\n';
}
Suzie999 commented: Very helpful, exactly what this noob needed. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

predeclare the structure

typedef struct tagPerson Person;
struct tagPerson
{
  // blabla
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You mean you want to sort the array without actually swapping array values? I have done that before but used a second array of intgers that represent the array indices.

float data[5] = {3,1,4,9,2};
int indices[5] = {0,1,2,3,4};

// sort the data
for(int i = 0; i < 4; i++)
{
  for(int j = i+1; j < 5; j++)
  {
     if( data[indices[i]] < data[indices[j]] )
     {
        int temp = indices[i];
        indices[i] = indices[j];
        indices[j] = temp;
     }
  }
}

// now display the values
for(int i = 0; i < 5; i++)
   printf("%f\n", data[indices[i]]);

This technique is a good way to sort large 2d arrays also because it greatly reduces the number of items to be swapped during sorting. The contents of the original array are unchanged.

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

A few problems:

1. There are more than 400 items in players.txt, so you need to increase the size of those two arrays

2. Add the ios::biary flag to the two binary files

3. When reading/writing binary arrays the arrays can be read/written all in one shot -- it is not necessary to write or read them one array element at a time. But sometimes it is more useful to read them one at a time if you don't know how many were written.

4. Move the class plr up above main() so that you can write other functins that use the same class. Almost no programmer will put the class definition within a function because it limits its scop to that one function. Not a very useful thing to do.

5. Instead of that array it would actually be better to use either std::vector or std::list so that you don't have to know how many items are in the files. Buth vector and list grow as you add items to them.

#include <fstream>

#include <iostream>

using namespace std;

  class plr
    {
    public:
      int id;
      int shirt_no;
      int age;
      int goals;
      int pos;//0-GK,1-DEF,2-MID,3-ATT
      char LName[51];
      char FName[51];
      int team;
      int skill;
      int goaltime;
      int cards;
      void transfer(int t_id)
      {
        team = t_id;
      }
      plr() 
      {
          id = shirt_no = age = goals = pos = 
              team = skill = goaltime = cards = 0;
          LName[0] = 0;
          FName[0] = 0;
      }
  };

int main() …
anantk commented: thanks +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh you poor boy. It must be tough having to put up with sooo many holidays. :)

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

I suppose ther are as many ways to write a logger as there are progammers. The way I did it was to write a funtion that took a const char* as parameter (the message to be logged), open the log file, write out the message, then close the file. Its a very simple function. Then you can call that function as many times in your program as you want to.

If you only want to do the logging when the program is compiled for degging then you might do something like this:

void log(const char* message)
{
#ifdef _DEBUG
   // code to log messages go here
#endif
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

%ls also works (see this man page) swprintf(buf, sizeof(buf)/sizeof(buf[0]), L"G%lsY", L"AMEDA");

N1GHTS commented: extra credit! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what eactly do you mean by "using events"? c++ is not event driven.

NicAx64 commented: may be signal driven (posix signals) :) +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know the answer to your question. But I am putting myself in into this for learning purpose.
I have not seen this function used in any c program that I have come across in my short experience with C. Can you brief about what exactly is the purpose of wide characters. I referred Google and now know what is wide characters but if you can give some examples where all this is used in real life, I would be grateful.

Wide characters wchar_t is used in UNICODE programs, which may or may not be English. Some character, such as Chinese, will not fit in one-byte char, so they use wchar_t. The sizeof(wchar_t) is not consistent among operating systems -- MS-Windows sizeof(wchar_t) == 2 while *nix its 4. So you have to be very careful about transferring unicode-witten files from one os to another.

sree_ec commented: Thanks... +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you are seeing the difference between %s and %S (not the capitalization os s and S).
with swprintf():
%s assumes the parameter is a wchar_t*
%S assumes the prameter is char*

The rule is just the opposite with sprintf()

This illustrates the difference

int main()
{
    wchar_t buf[255] = {0};

    swprintf(buf, sizeof(buf)/sizeof(buf[0]), L"G%sY", L"AMEDA");
    printf("%S\n", buf);
    swprintf(buf, sizeof(buf)/sizeof(buf[0]), L"G%SY", "AMEDA");
    printf("%S\n", buf);

}
N1GHTS commented: This answer saved me long hours of trial and error +1
sree_ec commented: I dint know that %s and %S existed :D +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I already told you with the code I posted above. It does exactly what you are asking. I just put the numbers in an array of integers rather than in individual variables. Just put the code I gave you in a loop that uses fgets() to read the file one line at a time, so that you know the begenning of each line.

Or if you know there will always be 4 numbers on each line and that it will never ever be anything else

int userID;
int time;
int from;
int to;
FILE*fp = fopen("filename.txt","r");
while( fscanf(fp,"%d%d%d%d", &userID,&time,&from,&to) > 0)
{
   // do something with the data
}
fclose(fp);
SamSmiles commented: Was very nice and helpful +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have a lot of syntax errors in your program. Here's the correctins. I added another parameter to that function -- the size of returnbuf. I didn't test it out because I don't have a copy of that database.

#include <iostream>
#include "cppSQLite3.h"
#include <string>
#include <string.h>

using std::string;
using std::cout;
using std::cin;

char* GetDirectory(const char* Subdomain,const char* PCD,char * returnbuf,int bufsize);

int main()
{
    char InstallPath[255] = {0};
   char Subdomain[] = "{A334FDED-DCCA-481E-B226-F902CCC419D2}";
   char Path[] = "C:\\Program Files (x86)\\Common Files\\Adobe\\Adobe PCD\\pcd.db";
   char* p = GetDirectory(Subdomain, Path, InstallPath, sizeof(InstallPath));
   if( p != NULL)
      cout << InstallPath << '\n';
   else
      cout << "GetDirectory() failed\n";
}
char* GetDirectory(const char* Subdomain,const char* PCD,char * returnbuf,int bufsize)
{
        //Write a function to get the installation directory.
    try
    {
       CppSQLite3DB db;
         std::string command;
    command = "select value From domain_data where SubDomain = '";
    command += Subdomain;
    command += "' And key = 'AMTConfigPath';";
    db.open(PCD);
       CppSQLite3Query q = db.execQuery(command.c_str());
       db.close();
const char* p = q.fieldValue(0); //Without the one in bold, error message: error: invalid conversion from 'const char*' to 'char*' is thrown.
if( p != NULL)
   strcpy_s(returnbuf,bufsize,p);
    return returnbuf;
    }
    catch (CppSQLite3Exception& e)
    {
      return NULL;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
void City::setNextCity(City city) {
    nextCities->push_back(&city);
};

You can't do it like that because the parameter is a copy of City class, and will be destroyed as soon as setNextCity() exits. You need to make list own all the memory so that it doesn't rely on anything outside of it.

Just off the top of my head this is how you will have to do it. Note that you will also have to add a copy constructor to City class.

void City::setNextCity(const City& cty) {
    nextCities->push_back(new City(cty) );
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are wasting your time and efforts trying to optimize that. There are only a few clock ticks difference between the two, and any optimizing you do with that will not even be noticable.

Concentrate first at the function level -- do some profiling to see where the bottle necks are.

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

Well you had better use a different compiler becuse you can't access win32 api mouse functions from that 16-bit compiler. MS-Windows != MS-DOS.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
while(true)
{
   Read previous post;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Look at that CppSqlIite project and header file. execScalar() returns an int, not a string. Therefore strcpy() will not work. Read this and find out how to get the result set after the query. (that's the same link you posted in your original thread starter post.)

And you need to add SqLite3.cpp to your program's project because it has to be compiled along with your program. You could make it a library if you want to, but that isn't necessary if you are using it for only this project.

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

Does Tom Hudgson = Glass Joe?

Must be nice to get paid for playing games :)

Do you know if its available on MS-Windows 7? Or just PSN and Xbox Live? Oh well, its probably too difficult for an old man like me anyway. I have yet to play Donkey Kong :(

Glass_Joe commented: Haha too funny +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use strftime() and you can format the date any way you want. All you need is a struct tm object. And you can get that from either localtime() or mktime()

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

Not harsh -- tough love :)

Normally you will want to break down the problem into its simplest parts, then code them one at a time -- divide and conquer style. Compile and test each part before going on to the next part. The worst thing you can do is to write 100 lines of code without compiling it. Compile and fix compile errors frequently. When you get several compiler errors, fix the first one then compile again to get a new list of errors. Fixing one err may actually fix a million other errors.

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

First you have to write an OnTimer() event handler. That is a function that you want MFC to call every second. This example has it in CMainFrame, but you can put it in any of the CWnd derived classes, such as CMyDialog. You can have up to 10 timer events active at the same time, so nIDEvent parameter just tells which event is being called. You set that event number when you start the timer, explained below.

void CMainFrame::OnTimer(UINT nIDEvent) 
{
   MessageBeep(0xFFFFFFFF);   // Beep
}

Next, you have to turn on the timer somewhere in the code.
m_nTimer = SetTimer(1, 2000, 0);

  • The first parameter is an id number that you want MFC to use to identify the timer event. The OnTimer() function will be passed that number (see above)
  • The second number is the number of milliseconds you want the timer event handler to be called. The example shows it wants the event to be fired every two seconds.
  • The last parameter is a pointer to the function you want to be called. If that parameter is 0 (or NULL) it is assumed to be the OnTimer() method of the MFC class in which SetTimer() is called. Otherwise, if the prameter is Not called then it can be any function you want. See the SetTimer link for a more detailed explaination.
  • The return value is the MFC id of the timer event, if SetTimer() is successful. Use this value to pass to KillTimer() to …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What you want is a character array char buffer[255]; That declares an array of 255 characters. c++ also has a std::string class, but you can not use that with SqLite database.

You have to be careful about allocating new memory in a DLL. Memory allocated in a dll with new or malloc() must also be destroyed in that same dll. (std::string allocates memory like that) So you would need to declare that function like this: char* DLL_EXPORT GetDirectory(const char* Subdomain, char* returnbuf) where returnbuf (or whatever you want to call it) is a character array allocated by the calling function and used by GetDirectory() to store the string it needs to return. The return value of that function is just returnbuf, or NULL if an error occurs. You could also make the return value just a bool, indicating either success or failure.

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

>> It should be a multiple of 4 bytes.
Depends on the compiler and how it aligns the structure object. You can change the alignment with most modern compilers so that it is 1, 2, 4, 8, 16, 32 etc aligned. The default alignment is compiler dependent too.

mrnutty commented: Thanks for the info. +5
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your program will get a runtime error because vector entity doesn't have any elements, so all those assignments in lines 9-15 will fail.

>>if(strcmp((*tokens), ',')

If you only want to compare two single characters to see if they are the same then why use strcmp()?? Just use == operator to compare them

for(i=0; i<tokens->size(); i++)
    {
        for(j=0; j<7; j++)
        {
            matrix.push_back(vector <char*>());
            if(strcmp((*tokens)[i], entity[j])==0)
                do{
                    i++;
                    if( *tokens->at(i) == ',' || *tokens->at(i) == ';')
                         strcpy(temp, tokens->at(i));
                }while(*tokens->at(i) == ';');
        }        
    }
nirali7 commented: you're awesome!!! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are correct, I have never used Xbox Live. And from what you just posted I don't really want to :) I now understand why you called them idots -- maybe you were right afterall.

Glass_Joe commented: I like you +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ditch that tutorial you are reading and try this one. Its been around for many years and has been used by hundreds of people. You need a basic knowledge of C language -- if you don't have it then you might be in trouble. The turotial comes with complete source code that you can download, compile, and run.

tux4life commented: :) +8
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

it doesn't work because you have to use sprintf() to format the string.

char command[255] = {0};
sprintf(command,"copy %s.jpg \\%s\\%s.jpg" , a, a, a);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Read about the format specifiers! The 2 in %2d says to display the integer in 2 or more characters. For example if x = 1, then it will show a space before the 1, like in " 1". But if x = 123 then it will just show all the difits, such as "123".

If you want the number left-justified in the field then use "%-2d". In that case it will display "1 ", with the space on the right instead of the left.

If you want 0 filled to the left, then use "%02d", and when x = 1 it will display it as "01" instead of " 1".

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

.bmp files are binary files, not ascii text files. You have to open the file with ios::binary flag and then use ifstream's read() method to read the binary data. getline() will not work. And you will have to read the file into a character array, not a std::string object

char readbuf[255];
ifsteam in("filename.bmp", ios::binary);
if( in.is_open() )
{
   while( in.read(readbuf, sizeof(readbuf)) )
   {
       int bytesRead = in.gcount(); // get number of bytes read
       // blabla
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I managed to read the whole file in one string

No you didn't. fgets() will not read the entire file into a single character array because fgets() stops reading when it encounters the first '\n' -- which is the character that terminates a line. So all your program will do is read the first word in the file.

>>Is there a way too keep this dictionary in a variable in C
Use a linked list of words. AFAIK there is no limit to the number of words that can be store in memory that way, except of course the amount of available RAM and hard drive swap space. Hopefully, you are not foolish enough to use a 16-bit compiler such as Turbo C.

tux4life commented: Good catch :) +8
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try c# or c++/CLR

NicAx64 commented: sorry sir no CLR no .Net I'm working for a company which implements Linux based soultions,to our customers. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>can't figure out what I'm doing wrong
That doesn't surprise me since you can't even figure out where to post this question.

diafol commented: ha ha ha - his first and last post I take it. +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Good Evening

What? did I sleep through the entire Sunday? It's early afternoon where I live. :)

Welcome to DaniWeb anyway.

>>I was also wondering if there was a 3D/Animation section here
No. That's not to say there aren't people here who can discuss it with you here at DaniWeb. It won't be me though because I never did any of that.

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

or else u can do with strlen

for(i=0;i<strlen(s);i++)

You could, but you should never use strlen(s) in a loop like that unless the length of the string changes somewhere inside that loop. Why? Because the program has to call strlen() function on every loop iteration, whould could be very very time consuming, making your program slow.

Instead, either check for the string's null terminating character as previously posted, or set an int to the value returned by strlen() and use it in the loop.

int len = strlen(s);
for(i = 0; i < len; i++)
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It would depend on the size of the file and how the file was written. If the file is relatively small (less than 100 meg or so) and the computer has lots of free ram then reading the file into memory and searching would be the fastest.

If each record of the file contains multiple fields, such as name, age, street, city, zip etc. etc, then a fix-length binary file can be read a lot faster than a simple text file becuse an entire record can be read at one time. And if the file is already sorted by the search field then you can use binary search algorithms on it. But sorting the file before searching would probably not be very efficient unless there were multiple searches on the same field.

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

Interesting. On MS-Windows I get the same results that you got on Solaris, which is correct. That book is wrong. The operating system may read into memory any amount of the file it wants to (buffering), but the file pointer only moves to the location requested in the program. There is little, or no, connection between the operating system's buffer size and the location of the file pointer.

Why the difference on RHEL, I don't know. Maybe there was some other kind of error.

initial file handle :: 0
child read :: abcdefghij
child file handle :: 11
parent file handle :: 11
parent read :: lmnopqrstu
end file handle :: 22
Press any key to continue . . .

#include<stdio.h>
#include <Windows.h>

FILE* fp = 0;
char buff[11] = {0};

DWORD WINAPI ThreadProc(void* lpParameter)
{
 printf("initial file handle :: %d\n",ftell(fp));
  fread(buff,sizeof(buff),1,fp);
  buff[10]='\0';
  printf("child read :: %s\n",buff);
  printf("child file handle :: %d\n",ftell(fp));
  return 0;
}


int main()
{
    fp = fopen("TextFile1.txt", "r");
    DWORD dwThreadID = 0;
    HANDLE hThread = CreateThread(0,0,ThreadProc,0,0,&dwThreadID);
    WaitForSingleObject(hThread,INFINITE);
  printf("parent file handle :: %d\n",ftell(fp));
  fread(buff,sizeof(buff),1,fp);
  buff[10]='\0';
  printf("parent read :: %s\n",buff);
  printf("end file handle :: %d\n",ftell(fp));

}
Jishnu commented: Thanks a lot! +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That program is only processing the last line of the file, not the entire file's contents. Each time getline() is executed on line 18 it replaces the current contents of variable line with another string that is read from the file -- in otherwises getline() doesn't just tack the new string to the end of the existing string's contents.

line 35: >> if(a=' ')
pointer a is completely unnecessary. You can index into std::string the same as char*.
Use the == boolean operator, not the = assignment operator
That if statement is 100% wrong anyway.


for(size_t i = 0; i < line.length(); i++)
    {
        words[r][c1] = line[i];
        if( line[i] == ' ' || (i+1) == line.length()) 
        {
            words[r][c1] = 0; // null terminate the word
            r++;              // advance to the next word
            c1 = 0;           // reset to beginning of new word
        }
        else
            c1++;
    }

And there are other ways to accomplish the same thing. The above is just one of them.

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

I would consider such emails as spam and a big turn off. I would not want DaniWeb to send me such emails. It is no big deal and most members probably could care less whether a thread is marked solved or not.

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

Turbo C huh? HaHaHaHaHa. What os is your computer running? MS-DOS 6.X or maybe Windows 95? If yes, then you don't really have any other choice because none of the modern compilers will run on those operating systems.

Why did I say your program is wrong? Just read my previous post from yesterday.

creeps commented: Couldn't agree more with everything he had written in that topic +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>i think it's..

Wrong. Where do you guys learn to program -- from a box of Craker Jacks ?