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

maybe you may just try to POST REPLY rather.

Good Grief :S don't do that or you will get flagged as an idot and hijacker.

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

have you made any attempts at all to write/code that program? If you have then post what you have done so far. We don't do homework but we will answer specfic questions you might have about it.

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

create a for loop and increment the loop counter by two -- inside he loop call printf() to display the value of the loop counter.

Or maybe I misunderstood the question.

get a number from the keyboard
multiply it by 2
call printf() to display the result

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

I don't get it. How is that matrix calculated?

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

What operating system? MS-Windows you can use win32 api drawing functions. There is some code here that may get you started. That just shows how to draw a circle. There are other win32 api functions to fill it in with a color of your choice.

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

Ok so I was wrong about that (I tested it wih two / characters and it works.)

Try a simple program like this and see if it works or not

#include <iostream>
#include <string>
#include <sstream>

int main()
{
    std::string filename = "c://dvlp//test2//test2//";
    for(int n = 1; n < 100; n++)
    {
    std::stringstream str;
    str << filename;
    str << n;
    str << ".txt";
    std::cout << str.str() << '\n';
    }

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

Yup, you are right. That does work :)

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

If you want variable choice to contain either a number or a chracter then you will have to change its data type to char instead of int. Then the cases would become

bool done = false
while( done == false)
{
  // display menu here
  char choice;
  cin >> choice;
  switch(choice)
  {
    case '1': // blabla break;
    case '2': // blabla break;
    case 'c': done = true; break;
  }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>filename="Synthesis//"+itoa(SynthNumber)+".txt";

I suspect that is the line that is wrong. The result of that is "Synthesis//1.txt", which has two / characters, not one. \ is the escape character, not /. So filename="Synthesis\\"+itoa(SynthNumber)+".txt" would be correct. If you want to use / then ok but you only need one of them.

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

Each of those arrays have to be serialized individually as if they were not part of a structure. Serializing just the structure is useless. You need to preceed each string with its length so that the receiving computer program knows how much data to expect and how to reconstruct the arrays and structure.

Serializing to a serial port is exactly identical to writing it to a text file. I'd serialize it to a text file first to get the algorithms down then change the stream to a serial port.

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

In that case then the compiler might be complaining about one of the parameters.

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

That has two two-dimensional arrays of unknown sizes, and a one-dimensional array of unknown size. How does the program that uses that structure know their dimensions? Without knowing the dimensions it will be impossible to serialize it anywhere, much less actually use it for anything.

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

OMG You can learn to create a c++ library in about an hour (or less). With VC++ 2010 Express (and older versions) I can create one in less than one minute. If you have to take 3 months to do that then you are wasting everyone's time.

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

make sure the *.cpp file includes fstream before class_array.h and add std:: friend std::ostream& operator<<(std::ostream& out,const Array& arr);

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

If the following doesn't fix the problem then the problem is in the way the data is being input as posted in your first code snippet.

int i,n1;
FILE *file = fopen("db.dat", "wb"); 
cout<<"Writing into file\n";
if ( file != NULL )
{ 
    fwrite(r, sizeof(r[0]), n,file); 
    fclose(file);
}
cout<<"Writing completed\n";

and

struct rec re;
FILE *file = fopen("db.dat", "rb"); 
while( fread(&re,sizeof re,1, file) > 0)
{
  cout<<re.id<<re.name<<re.mark<<'\n';
}

Since this is a c++ program you really should use ofstream and ifstream classes instead of FILE*.

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 ?

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

Does that string represent hex numbers? such as "0A" ? If yes then you don't want to skip the alpha characters. Call strtol() to make the conversion. The last parameter to that function should be 16 (base 16 is hexidecimal).

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

Ask your school counsoler.

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

I had a woman as a team leader for nearly 10 years before I retired three years ago, and I can say that she was just as competent as any of the men who worked for her.

As for age -- over 50% of the 200 people who worked for that company were over the age of 50, most of them retired military like me. I didn't feel the least bit of discrimination.

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

Welcome back. But that means you're only 14 now. A little better, older, and wiser, but not much. Stick around until you are at least 18 and you might have a little common sence by then :)

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

you have a couple options

1) call setenv() function. The variable will disappear when the c++ program exits.

2) write a shell program to call your program and capture its return variable. Then return the value of the variable from main() so that the shell program can grab it and set the environment variable. Remember that the shell program will have to export the variable ot it will disappear when the shell program terminates.

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

It will depend on the company you want to work for, but equivalent experience usually means a paid job for at least 4 or more years. Just doing hack work between ages 10 and 14 don't do it. Somebody needs to pay you $$$ for your work.

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

You would be right if this thread was about iterators. It isn't, so you aren't.

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

Because you need to add { and } around lines 30-32. The break statement is not within the if statement, so the loop on line 21 exits on the first iteration of that loop.

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

Unusual and unconventional approach. If you are going to do that then you might as well use a while loop instead of a for loop.

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

If you are so smart why can't you figure this out yourself?? Smart boys and girls will at least attempt to solve the program and post what they have done. They also read the forum Rules and know that we don't do people's homework for them.

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

Pass it just like you would any other array

class foo
{
public:
    foo(char **ar, int n)
    {
    }



};



int main()
{
    char** mz = new char*[5];
    for(int i = 0; i < 5; i++)
        mz[i] = new char[5];
    foo f2(mz,5);
}

[edit]Oops! Sorry Narue, I didn't see your post.

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

Other options:

1) Get the source code and compile them yourself with whatever compiler/IDE you want

2) Make one of them a DLL

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

Never ever for any reason whatsoever include one *.cpp file in another. Even C# does not do that. Each *.cpp file has to be compiled on its own and then all of them linked together at link time. Exactly how to do that will depend on the compiler/IDE that you are using.

As for public data used in multiple *.cpp files: Just add the declaration in the *.h file but use the extern keyword, such as extern Resources res; . That just tells other *.cpp files that the object will be declared publically in some other *.cpp file. Then do NOT change the declaration as you have it in main.cpp because that's the one that actually creates the object.

Similar with function prototypes. Just put them in header files with or without extern keyword, then write the implementation of the function in one of the *.cpp files.

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

The instructions are a little unclear. Is the data coming from a text file, or do you have to input it from the keyboard, or both?

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

Get OpenOffice -- it is free and compatible with M$ Office.

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

The main reason for the seg fault is in this function. If the first read failes then you need to return ifs.

ifstream &operator >>(ifstream &ifs, Person &p)
{
	short length;
	char *name,*addr,*ph;
	ifs.read((char *)&length, sizeof(length));
	if (!ifs || length==0)
		return ifs;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 13: name needs to be larger than 30 characters. Most people's names are at least that big, unless its something like "Mike Smith". You need to make it large enough to hold any reasonable-length name.

line 33: cin >> does not allow spaces in the name. So "Eter full name" does not work if you want to enter first and last name. Use getline() instead. Now use getline() for the other questions too because they have the same problem.

line 43: buffer size might be too small. Declare it something like this to avoid the problem char buffer[sizeof(Person)+16] = {0};

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

1)seek to end of file

Start of loop
   Read a record
   // back up two records, 
   file.seekg(-(2* sizeof(Transation_Info), ios::cur);
   beginninng of file?
     yes, then exit loop
end of loop
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

@brp003: The code you posted is a very good reason why you should NOT attept to learn C solely from the internet. There are lots of bad programming styles out there and what you posted is one of them.

Its int main()

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

In that case I have no idea what's wrong because I can't compile the code you posted -- I don't have OpenCV installed on my computer. But I would suspect there is some other problem since Example1 is just quoted text literal.

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

It might be compiler dependent, I don't know, but in VC++ 2010 Express references do not occupy memory

void foo(int& ref)
{
    printf("foo: %p\n", &ref);
}

int main()
{
    int ival = 123;
    int& ref = ival;
    printf("%p %p\n", &ival, &ref);
    foo(ival);
}

And the output is

0014FAC8 0014FAC8
foo: 0014FAC8
Press any key to continue . . .

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

And don't expect to do it overnight -- for some people it might take months or years.

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

There are probably lots of way to do it. One of the easiest is to create a fixed-length structure then save it to the file in binary format

struct person
{
   char lname[40];
   char fname[40];
   char mi[3];
   int id;
   // other fields here
};

// save to a file
int main()
{
   Person p; // assume p is populated with some data
   ofstream out("filename.dat",ios::binary | ios::ate);
   out.write((char)&p, sizeof(Person));
}

[edit]Mike's suggestion is more appropriate if the records in the file need to be shared wih other programs wich already know how to read/write XML files. Writing files as I suggested would restrict those files to only the program(s) you write, and it is more difficult to change (add or remove) items in the structure.

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

Those errors are telling you that you are attempting to use something before it has been declared. If Example1 is a function then you need to provide a function prototype for it, or code the complete function before main() or whereever it is being called.

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

you don't want to use a union in your program because you need the value of all the object at the same time. unions won't allow that.

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

Here is one way to do it

int main()
{
FILE* fp;
unsigned char* buf = 0;
unsigned int size = 0;
// open the jpg file in binary mode
fp = fopen("filename.jpg","rb"); 
if(fp == NULL)
{
   printf("Error\n");
   return 1;
}
// get file size
fseek(fp,0, SEEK_END);
size = ftell(fp1);
buf = malloc(size);
// back to start of file
fseek(fp,0, SEEK_BEG);
// read the file
fread(buf,1,size,fp);
// close the file
fclose(fp);

// now write out to new file
fp = fopen("newfile.jpg","wb");
fwrite(buf,1,size,fp);
fclose(fp);
free(buf);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Great news for people who play games. Now if they would just do the same with old movies :) I have a house full of movies I'd like to get rid of.

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

I just finished downloading and unzipping all the files for version 1.44.0 and did not have any problems. Make sure your hd has plenty of free space becaue boost is 308 mg and over 31,000 files.

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

After installing boost I think you have to compile it with your compiler to generate the lib and dlls.

Did you follow these instructions ? If you are using Window 7 do not attempt to unzip the files in c:\ root directory. PkZip does not have permissions to unzp them there. Put them somewhere else and move the folder to c:\ if you want to using Windows Explorer.

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

Yup, that's right. Pointers occupy memory too.

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