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

You could replace char* name with std::string name so that you do not have to allocate any memory for that variable. If that doesn't fix the problem then the problem is caused by something else in your program, such as buffer overflow somewhere else that is destroying the heap.

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

Read some of these links to get you started.

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

Let's say you have two *.cpp files -- A.cpp and B.cpp

cl A.cpp B.cpp
c. a.obj b.obj -o myprogram.exe

There are of course lots of other flags you can add but the above is the simplest.

If you bother to learn VC++ 2010's integrated IDE you wouldn't have to bother both those command prompt builds or what flags to use.

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

I've been using Code::Blocks on 64-bit Windows 7 for some time now and with none of the problems you described.

Are you reading this tutorial? If not then maybe you should

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

>>Any idea?

Yes, replace the relative path with full path to the *.lib file. You obviously have used the wrong relative path.

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

Those functions are not defined in the files you posted so they must be in another file or library that you need to add to the solution. Look in your 32-bit project and find out where those function are found.

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

When a file is opened in append mode, like AppendFile is, every write operation is done at the end of the file. Therefore fseek() will not do anything to resolve your problem. Open that file in "r+" mode then seek to end of file before writing anything.

>>Forget the fseek(). Just don't output the space when you've output the last value.
I would normally agree with that, but in this case it may not be possible to detect when the last item may be written. It would just be a lot simpler to back the pointer up one character then overwrite it with '\n'.

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

post the fopen() statement for AppendingFile.

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

Maybe you misunderstood the link I posted -- it has no limit other than computer memory. The author's example includes calculating 100!

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

Well I think I misunderstood the problem. Ignore my previous post.

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

Yes I agree some laws are wrong -- The efforts of Rosa Parks in 1954 is one example of where disobeying a law made sweaping changes in our society. And occasionally such protests, no matter how honorable, turn into tragedy (Tiananmen Square protests of 1989 come to mind).

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

What???

#include <stdlib.h>
#include <stdio.h>

int main ()

{
    int Tab[5][3]={0}, i, j, sum = 0, largest_sum = 0;
    
    for(i = 0; i < 3; i++)
    {
        for(j = 0; j < 5; j++)
        {
            scanf("%d", &Tab[j][i]);
        }
    }

    for(i = 0; i < 3; i++)
    {
        for(j = 0; j < 5; j++)
        {
            printf("%d\t", Tab[j][i]);
        }
        printf("\n");
    }
   largest_sum = 0;
   for(j = 0; j < 5; j++)
     {
       sum = 0;
       for(i = 0; i < 3; i++)
          sum += Tab[j][i];
       if( sum > largest_sum)
            largest_sum = sum;
     }
    printf("\n %d",largest_sum);
    
  return 0;
  
 }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>what is SEEK_CUR ?
Seek and thou shalt find.

>>this statement is it just like the '\b' ?

No it isn't. '\b' will put the '\b' in the file, seek() will not.

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

Maybe he is trying to ask what kinds of operating systems are in common use???

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

I don't know what w3m is, but do you mean someting like system("w3m"); ?

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

You need to find out what PVOID is defined to be. If it's not defined to be anything, such as define PVOID then the compiler will produce C4430. If you don't know what C4430 error is then look it up with google.

>>HAPTIK_DLL_IMPORT_EXPORT
Your program need to define that symble to be either dllspec(__import) or dllspec(__export) depending on whethere you are declaring it in a DLL or the application program that uses the DLL. Just putting a semicolon after it like you did is not the correct solution.

claudiordgz commented: Awesome response +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

One way to solve it is just before fprintf(AppendingFile, "\n"); call fseek() to move the file pointer backwards one character., such as fseek(AppendingFile,-1,SEEK_CUR);

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

your program looks ok until line 28. At that point all you have to do is sum up the three numbers on each of the 5 rows of the 2d array and display the largest sum value. You don't need GrandA, GrandB, or GrandC. just int sum and int largest_sum.

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

Using a 64-bit integer instead of 32-bit integer will help some. But here is no way to resolve the problem using native c or c++ data types. There are a few large number libraries around, such as this c++ class It uses a vector of digits in char form then manipulates the individual digits much like you would when using pencil & paper.

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

>>I should get an error message and not an incorrect value.

No. Its your fault, not the compiler's. A compiler can only produce erros/warnings on the code it sees at compile time. It knows nothing about runtime errors.

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

People who break the laws are more than just "disobediant" -- they are criminals. Just because you don't like a law doesn't give you the right to disobey it. Are there laws that shouldn't exist -- Yes, but the way to get around it is to change the law, not break it.

It sounds to me that you are much less intelligent that what you think you are. Breaking laws is not a very intelligent thing for you to do.

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

You could do this

class something
{
   public:
      char attribute1[25];
      char attribute2[25];
      donkey(char* a, char* b)
      {
          strcpy(attribute1,a);
          strcpy(attribute2,b);
      }
      donkey(){}
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You might find this thread interesting and useful

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

google is you friend, learn to use it. Click here

geojia commented: Haha, Very NICE! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The result of that program is compiler dependent whether on *nix or any other operating system.

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

Please explain the format of that file. Looks like <city nbame>;;<zip code>;<some other number, don't know what>;

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

If you are talking about an int or float array, the answer is no because there is no such value as infinity. Integers have maximum values, which are declared in limits.h header file.

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

How is the file formatted? Does it contain fixed or random length records? Binary file or text file? We have to know everything about the file before your question can be answered.

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

Look at this tutorial and maybe it will tell you what you are doing wrong.

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

What is it that you are trying to do? Very doubtful that anyone here knows how to read Chinese.

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

>>if no one answers my thread i cannot get to it again

See that purple ribbon at the bottom of the screen? It contains several links -- one of them is "Threads I've Posted In" and another "Threads I've Started". Just click "Threads I've Started" and DaniWeb will show you links to all the threads you have created, whether anyone has posted in them or not. Can't get much smipler than that friend.

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

Maybe you didn't notice but that post was 8 months ago :)

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

This makes more sense

bit running = 0;
float var1, average_value;


    void is_something_running(void) {
      running = (fabs(var1 - average_value) <= 0.001) ? 0 : 1;
      return running;
  }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 41 and 42 are duplicates. delete one of them.

Your program has a number of errors in it -- here is a corrected copy. I changed the indentation of some loops to make it easier for me to see what it's doing -- you can just ignore my style if you wish to keep your own.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#pragma warning(disable: 4996)

int main()
{
        FILE *infile;
        char line[150];
        int row, col, rows, cols, i;
        double **a, *b, *c;
        double dot_p;
        infile = fopen("matrix5.dat", "r");
        if(infile == NULL){
        printf("Error opening matrix5.dat!");
        exit(0);
        }
        fscanf(infile, "%d %d", &rows, &cols);
        printf("\n_________________________________\n\n");
        printf("There are %d rows and %d columns.\n", rows, cols);
        printf("___________________________________\n\n");
        a = (double **)calloc((size_t)rows, sizeof(double *)); // <<<<<<< HERE
        b = (double *)calloc((size_t)cols, sizeof(double));
        c = (double *)calloc((size_t)cols, sizeof(double));
        for(row=0;row<rows;row++)
        {
          a[row] = (double *)calloc((size_t)cols, sizeof(double));
          if(a[row] == NULL)
          {
                printf("Error creating row %d!", row);
                exit(1);
          }
        }
        printf("a[][]:\n");
        for(row=0;row<rows; row++)
        {
          for(col=0;col<cols;col++)
          {
                fscanf(infile, "%lf", &a[row][col]);  // <<<<<<< HERE
          }
          printf("a[%2d] ", row);
          for(col=0;col<cols;col++) 
              printf("%9.3f", a[row][col]);
          printf("\n");
        }
        printf("\n");
        printf("b[] ");
        //do{
        do{
        for(col=0;col<cols;col++){
          fscanf(infile, "%lf", &b[col]);
          printf("%9.3f", b[col]);
        }
        printf("\n");
        }while(row == rows+2);
        printf("\n");
        for(row=0;row<rows;row++)
        {
          for(i=0,dot_p=0.0;i<cols;i++)
          {
              dot_p += a[row][i] * b[i];
          }
          c[row] = dot_p;
        }
        printf("c[]");
        for(row=0;row<rows;row++)
        {
            printf("%9.3f", c[row]);// <<<<<<< HERE
        }
        printf("\n");
        for(row=0;row<rows;row++)
        {
            free(a[row]); // <<<<<<< HERE
        }
        free(a); // <<<<<<< HERE
        free(b);
        free(c);
        fclose(infile);
        exit(0);

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

It's missing the first file because your program is tossing it into the bit bucket. findfirst() finds the first file then your program immediately calls findnext(), which dumps the result from findfirst(). You need to rearrange the logic of that funcion so that it does something with the results of findfirst()

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

Your program compiled and ran ok for me using VC++ 2010 Express on 64-bit Windows 7. Here's the output I got, but I don't know if it's right or wrong.

1
2.5
3
3.5
3.6
5
6
7
7.9
8
8
9
10.5
12.6
14
45
Press any key to continue . . .
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Don't you think creating three threads for the same question is a bit much?

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

>>but the problem is once i enter '1', it ask me again the question

Because yuou have the question twice in your program, once on line 43 and again on line 56.

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

>>i need answer for my asingment,please
So what don't you understand about the assignment? Hint: No one is going to write it for you unless you pay them lots of $$$.

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

>>Second don't do any coding in the header file. If you want to in-line some code, do it in the implementation file with the in-line directive.

Here I disagree -- again matter of style, but I find it a lot easier to just put inline code in the class where its declared

class Hello
{
   void SayHello() { cout << "Hello\n"; }
};

If you let Microsoft VC++ 2010 compiler generate CLR/C++ project the IDE will put a lot of inline code inside the header files it generates.

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

you used the wrong index value in this loop

cout<<"enter the elements of the array";
                        for(int i=0; i<y; i++) // <<< this should be < y, not <= y
                        {
                           cin>>bector[i]; // <<<< this one
                        }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do you know how to read a file? Search and compare is the same thing except after every read you just compare the name.

hospital record;
char Name[] = "John Doe";
ifstream in("filename.txt"); // open the file
// use your operator>> to read each record
while( in >> record )
{
   if( strcmp(record.name,Name) == 0 )
   {
      // got it
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Now for that operator>>. That is supposed to read a record from the file, not write to it. >> is for read and << is for write. So it doesn't make any sense to ask all those questions in the operator>> function.

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

If you are asking me to write the code for you, my answer is no. What you will have to do is search the file for the patient's name and when found mark it for deletion. You will want to call fstream's tellg() before reading each pathent's record so that you can easily go back to the beginning of the record (by calling seekg()) when you have to mark it for deletion.

This is where good file design makes your programming efforts a lot easier. Rather than putting each patient's data on separate lines, put then all on one line so that you can read the entire patheit's record in one shot using getlin(). You can use tab character to separate individual items in the record. Something like this:

Also note that the hospital record parameter should be passed by reference, not by value. That will speed up your program quite a bit.

Next thing about file format is that you don't have to write the titles of each field inthe file.

ostream &operator<<(ostream &stream, hospital& o)
{
	stream<<o.name<< '\t'
	   <<o.id<<'\t'
   	   <<o.telephone<<'\t'
	   <<o.numday<<'\t'
	   <<o.numday*2000<<'\t'
	   <<o.roomnum<<"\n";
	return stream;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The only way to physically delete a record from the file is to rewrite the entire file. If the file is small enough then just read the entire thing into memory, then write it back out to the same file but omitting the record to be deleted.

Another method that I have used on occasion is to just mark the record for deletion, such as change the first character of the first item in the record to something that is not likely to be used for that item. If the first item in the record is someone's name then change the first character to '~'. Then when your program reads the file just have it ignore records whose first character is '~'. This is the same concept that databases use to delete records.

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

strncpy() is just like strcpy() but you can specify the maximum number of characters to be copied. But you have to be careful with that function because it will not null terminate the destination sting if the source string is longer than the number of characters you specfy in the third argument. For example, if the source string is "Hello World" and you tell strncpy() to copy only 3 bytes then strncpy() will not null terminate the destination string because "Hello World" contains more than 3 characters.

In the case of the code you posted it would be better if the writer had flooded the destination buffer with 0 before calling strncpy() just to make sure the sring is null-terminated.

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

Maybe you are searching for the wrong thing. Try this one.

sree_ec commented: for showing let me google that for you :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have two cases of vintage Bud Light beer (2+ years old now) that I'd like to sell.

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

anything except executable code/functions. There is no standard that says what you can and can not put in heder files -- its just common sense.

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

Yes, of course you can create java source files from c++. Once the java source code is created just run it though a java compiler.