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

delete this if statement: if(arr[i][j] > 0){

and this one: if(arr[i][j] > 0){

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

#define sizes 1200



 main()
{
    double** arr;
    int m[sizes];
    int i,j,k;

    srand((unsigned)time(NULL));

    arr= (double **) calloc(sizes,sizeof(double*));
    for(k=0; k< sizes; k++){
    arr[k]=(double*)calloc(sizes,sizeof(double));
    }

    for(j=0; j< sizes; j++){        

        for(m[j] = 0; m[j] <30, m[j]++){
            i= (int) rand()%1200;
            arr[i][j]= (double) rand()/RAND_MAX
            printf("arr[%d][%d] = %lft", i, j, arr[i][j]);
            printf("n");
        }
    }
    // FREEING MEMORY        
  for (k = 0; k<sizes; i++)    {        
      free(arr[k]);        

  }   
    free(arr);  

    getch();

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

That's right -- this is supposed to be C, not C++. C uses pointers, not references. so you want createGeo(geo* inst), then replace . with ->, such as inst->coords[0+jump][j][0] = j;

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

GLubyte indices[];

Declare that as a pointer and allocate memory for it on line 35, after you know how big it should be.

void createGeo(geo inst)

Pass that object by reference, not by value. such as void createGeo(geo& inst)so that any changes made by createGeo() are reflected in the object created in main()

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

This is what I have but it isn't working in the slightest..??

That program worked ok for me using VC++ 2010 Express on Windows 7. If its broken for you then I suspect that pheininger is correct in his assessment. Change int sixdigits to long sixdigits

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

This suggests that ofp might be NULL.

His program is already checking for that condition.

mitrmkar commented: Right - Indeed, it does. +13
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 10: > )malloc(sizeof(argv)

Wrong. sizeof(argv) is always 4 because its a pointer.

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

I hate not having an edit button!!!

"d.mkv"

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

Double-click on code to copy/paste it.

Great :) That answers my previous question about that topic. That is a litte easier than previous version of DW.

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

There was immense pressure to get this system rolling before a hard and somewhat unreasonable deadline,

Huh? Ms Dani owns DaniWeb so there should be no pressure to upgrade, she is free to do what she wants when she wants to. Only Ms Dani makes the deadlines.

But I'm not about to stop visiting DaniWeb just because there are a few problems with it now. It's still a great community.

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

Are you talking about moderator permissions? I have not seen a permissions problem.

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

We were all beginners at one time. The only way for you to learn is by coding it yourself, making mistakes, and learning how to correct your mistakes. There is a lot of self-satisfaction in knowing that you can accomplish something.

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

char* str[] is the same thing as char** str; , which is a two dimensional array where both dimensions are unspecified and must be allocated at runtime. char* str[5]; is also a two dimensional array, but in this case you have hard-coded one of the dimensions to be of length 5. That means where is room to store 5 strings of unspecified length.

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

If you use vector<int> then you can use std::sort() to sort the numbers.

start of loop
    read a line
    split line into individual integers and put into vector
    call std::sort
    display values
end of loop

you can do the same with simple int array instead of vector, but then you would have to write you own sort algorithm.

salem13 commented: can you give me a code to do this +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

They are all violent -- do something useful with your life instead of wasting it on stupid games.

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

[rant]
I'm not voting for anyone who phones me with political message. So if any of those annoying Republican candidates want the job of President, don't call me again. So far, Mitt Romney is on my shit list.
[/rant]

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

TCHAR is a macro -- you can't convert System::String to a macro, it doesn't make any sense. You can convert it to char* or wchar_t*, depending on whether you are compiling for UNICODE or not, but can't convert it to a macro.

See ToCharArray() here

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

>>#define p printf
>>#define s scanf

Horrible misuse of macros. Don't be so lazy and just type out the word printf and scanf when needed.

>>Link list strings stored rewrite this program

The structure is incorrect. You need to add the star to the declaration making nbook a pointer so that its length can be allocated to fit the size of the string you want to store there.

struct node
{
char* nbook;
struct node *next;
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That will not work with some languages that must be represented in two bytes.

If the file is in UTF-8 format then the first 4 bytes will represent a binary number between 0 and 0xffff. The table in that link tells how to interpret those bytes. If the first byte does not have a maximum value of 0x0f then the file is not in UTF-8 format. You can assume standard ascii file format, or possibly UTF-16 or UTF-32 format.

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

>>for(int LineCount = 1; !InputFile.eof(); ++LineCount)

That is the wrong way to read input file because eof() doesn' work like that for( line LineCount = 0; getline(InputFile, InputFileLine); ++LineCount) The >> operator doesn't accept space in the input, while getline() does. That assumes InputFileLine is of type std::string.

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

Here is an explanation of utf8 file format. Note that the first two bytes may be a binary integer -- see the chart at the end of that link.

Tygawr commented: Thanks for the link. +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Real programmers don't need Intellisense because they have memorized the syntax or know how to read the docuomentation and all that does is slow them down :)

zeroliken commented: right :) +9
PrimePackster commented: That's a advice worth taking..... +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Call fgets() to read entire lines of a file

char line[255] = {0};
myfile=fopen("garrudaRanch.txt ","r+");
if( myfile != NULL)
{
   while( fgets(line, sizeof(line), myfile )
   {
         // do something
   }
   fclose(myfile);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>so i can skip the "int strSize = sizeof(str);" in every function.

Just as well because sizeof does not return the length of the buffer, only the size of a pointer (which on 32-bit compilers is 4). What you will probably have to do is pass the size of the array as another argument to the functions, such as void printstr(char str[], int size);

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

The only difference would be to change the 4 (which is the size of a 32-bit integer) to the size of a float, whatever that is.

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

there is no problem with malloc() -- what you see is called undefined behavior, or array out-of-bounds error. The compiler won't complain about it because it assumes (usually wrongly) that you know what you are doing. What happens when you do that? The program just scribbles stuff all over memory, destroy whatever happens to be in memory at the time. Sometimes your program will crash, and sometimes not, depending what was in memory at the time.

The way to fix that problem -- Don't do that :)

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

Too bad C doesn't have an ArrayList class like Java or Vector like in C++ ;)

Then it wouldn't be C, would it? :)

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

One common way is to allocate memory in fixed block sizes. When that fills up then allocate a larger array. Here is an example

int array_size = 0; // initial array size
int elements_used = 0; // current number of elements used in the array
int *array = NULL; // initial array is empty

#define BLOCKSIZE 10 // allocate this many elements at a time

int main()
{
   int number = 0;
   for(;;) // infinite loop
   {
      printf("Enter a number\n");
      scanf("%d", &number);
      // check for array overflow
      if( (elements_used+1) >= array_size)
      {      
          // stretch the array
          array_size += BLOCKSIZE;
          array = realloc(array, array_size);
      }
      array[elements_used] = number;
      ++elements_used;
   }
}
DarkMonarch commented: helpful tip +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to format that char* before calling TextAdd(). There are several ways to format it, one way is to use std::stringstream from <sstream> header file, another way is to use sprintf().

#include <sstream>

int main()
{
   int score = 123;
   stringstream str;
   str << score;
   std::string s;
   s = "Score: ";
   s += str.str();
}

or

#include <cstdio>

int main()
{
   int score = 123;
   char text[80];
   sprintf(text,"Score: %d", score);
}
SgtMe commented: just what I needed...thanks :) +8
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The reason is there is a maximum value that an integer can hold -- the maximum is declared in the header file limits.h that is supplied by your compiler. What you are seeing is called numeric overflow.

If you need bigger numbers then use a bigger integer, such as "long long", which holds about twice as many digits as an int or long. There are no standard C or C++ data types that will hold an infinite number of digits.

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

Really?? How do you get ardav out of mississippi?

iamthwee commented: +1 for satire +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 30-32: the value of k is a negative number when i is 0. Do the first time through using k as index is illegal because there is no such thing as -1 index of arrays.

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

>> for (int n=0;n<=99 ;)

What makes you think there will be 99 characters in the string? You should use this: for(int n = 0; n < words.size(); ) Also not that you should use <, not <=

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

Torrents in and of themselves are no more illegal than any other program. Its how you use the torrent that can become a legal issue.

jbennet commented: yup thats what I was saying +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>how can i access the variables of my "xyzView.cpp" file in the Dialog Box

CDocument class contains a linked list of CView classes. So first you have to get a pointer to CWinApp by calling AFX::GetApp(), then from that pointer get a pointer to CDocument using its GetNextDocumenTemplate() method. Since MFC is just c++ you will have to make sure that the variables have public access in CWin class by either making the variables public or having public getter and setter methods.

>>but i want to know, how can i print a 2D-Array in MFC SDI?

Similar to the way you would with cout but you have to covert the data to a string first. cout makes that conversion for you -- in MFC you have to do it yourself. You can use any of the standard C or C++ functions to do that.Formatting the string is the easy part -- calculating the exact pixel location where it is to be printed may be more problematic.

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

The trick to writing complex programs is to break it down into much smaller parts. For example the first thing you want to do is write a program that lets you enter the date as a character array. Once you have that working, take the char array and break it down to its integer parts -- day, month, and year.

Most programs that calculate that sort of thing use an array for very quick lookup of the number of days from 1 Jan to the 1st day of the desired month. We know that January always has 31 days, as do several other months. So we can just create an array like this:

int days_of_months[] = {31, // January
                        28, // February
                        31, // March
                    // etc for all 12 months
};

And for days in year

int days_in_year[] = {0, // January
                      31, // 1 Jan to 1 Feb
                      59, // 1 Jan to 1 March (ignoring leap year)
                      89, // 1 Jan to 1 apr
                // etc. etc for the remaining months
};

With the above, its pretty simple to figure out the number of days from 1 Jan to the 1st day of any given month by just using the month number as the index into the array. int days = days_in_year[ month ]; Once you have done that, then just add the day of the current month. So if you have a date string "15 February 2012" (where January = 0, February = …

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

That's because you have to either add a call to keyboard input so that the program waits for you to press a key, or run it in its own cmd window.

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

or

while( in_stream >> name >> combo >> op1 >> op2 >> op3 >> op4)
{
   // do something with the data
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Visual Studio most certainly does contain a c++ compiler. You can get vc++ 2010 Express for free, as well as vb.net and C#. It's the best compiler suite there is for .net framework, afterall it is produced by the same company that wrote .net -- Microsoft. You can't get a better compiler suite.

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

It's not all that difficult to do. Here's an example of push_back

const int BlockSize = 10; // allocate this number of elements at one time
int MaxArraySize = 0; // initial size of the array
int CurrentSize = 0; // current number of elements used in the array

char** array = 0; 

void ReallocArray()
{
   MaxArraySize += BlockSize;
   array = realloc(array,MaxArraySize);
}

char* push_back(const char* item)
{
    if( (CurrentSize+1) >= MaxArraySize )
    {
       ReallocArray();
    }
    array[CurrentSize] = malloc(strlen(item)+1);
    strcpy(array[CurrentSie], item);
    ++CurrentSize;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

LPCWSTR is a pointer to TCHAR so just use the & address operator to make the conversion
TextOut (hdc, 40,40,&chCharCode, 1);

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

I wrote a test program to test my theory. The program contained two test cases, both created a linked list with 100,000 nodes and called clock() to time each of them.

case 1: linked list that inserted new nodes in correct places, searched sequentially from the beginning of the list and stopped when the correct position was found.

case 2: Inserted all new nodes at the tail end of the list, then used bubble sort algorithm to sort them.

Result: case 1 = 83413 clock ticks, case 2 = 37,753 or less than have the time of case 1. The time difference could be even greater had I used a more efficient sort algorithm.

#include <ctime>
#include <iostream>
#include <cstdlib>

struct node
{
    struct node* next;
    int data;
};

const int MaxItems = 100000;

void insert(struct node**head, int newdata)
{
    struct node* n = new struct node;
    n->data = newdata;
    n->next = NULL;
    if( *head == NULL)
        *head = n;
    else
    {
        struct node* curr = *head;
        struct node* prev = curr;
        while( curr && curr->data < newdata)
        {
            prev = curr;
            curr = curr->next;
        }
        if(curr == *head)
        {
            n->next = *head;
            *head = n;
        }
        else
        {
            n->next = prev->next;
            prev->next = n;
        }
    }
}

void ShowList(struct node*head)
{
    while(head->next)
    {
        std::cout << head->data << '\n';
        head = head->next;
    }
}

void FreeList(struct node** head)
{
    struct node* n = *head;
    while(n)
    {
        struct node* h = n;
        n = n->next;
        delete h; …
WaltP commented: Very kool! Thanks. +17
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first function is incorrect

void print (string word)
{
	cout << word << '\n'; // display the string
}

Now do similar for second function, but this time put cout statement inside a loop.

zeroliken commented: simple as that +8
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here's a link for MS-Windows (and it won't matter which 32-bit compiler you use. It won't work with Turbo C or Turbo C++)

DeanMSands3 commented: Rock on, Ancient Dragon. +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Have you tried this?

thines01 commented: Excellent Suggestion! +12
DeanMSands3 commented: Thank you, Ancient Dragon. You've changed my life, and my forum posting career, forever. +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It might simplify the program if you write two more functions: 1) a function that inserts a new node into the list in its correct position, and 2) a function that displays all the nodes in the list. Then main() can contain a simple loop

void InsertNode(node**head, node*p)
{

}

void DisplayList(node* head)
{

}

int main()
{
   node* head = NULL; // top of linked list
   node* p = NULL; // a new node
   while(true) // an infinite loop
   {
      p = new node;
      cout << "Give a number: ";
      cin >> p->data;
      p->next = NULL;
      InsertNode(&head, p); 
      DisplayList(head);
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Up or down voting a post anonymously doesn't affect the person's rep points. All it does is show whether or not you liked the post, nothing more. That is not the same as the question you posed in the poll.

zeroliken commented: I upvoted this post, Just because :) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to use an array of ints, one for each task. Or if you know there will be only 4 tasks then you can use 4 different int counters

int count1 = 0, count2 = 0, count3= 0;
int main(){
int option =0;
bool exit = false;
while(!exit) {
displayMenu(option);

switch(option) {
case 1:
doTaskA();
count1++;
continue; 
case 2:
doTaskB();
count2++;
continue;
case 3:
doTaskC();
count3++;
continue;
case 4:
howMany(count1,count2,count3);

exit = true;
break;
default:
printf("Incorrect selection. Try again.\n");
continue;
}
}

return 0;
}
[
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The only way to find out how many times you executed the program is to write a value to a file or the registry. Programs can not retain values from one instance to another.

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

>>why it is assigned i=1

That's called initializing a variable to some known value. The value 1 was arbitrary, would have been any number. The important point is that the value is something that the author knows. Programmers would normally initialize variables to 0.

>>why it has given i<=10

So that the loop can count from 1 to (and including) 10. Had the value of i been initialized to 0 instead of 1, then the i<=10 would have been i<10. In either case the loop will execute 10 times.

>>why i++ is given after printf statement.
That increments the value of i by 1.

Another way that loop could have been written is like this

for(i = 1; i <= 10; i++)
{
    printf("\n %d x %d = %d", num, i, num * i);
}

When learning to program a good way to help you understand the code is to compile and test it yourself. don't be afraid to change the code a little to find out what happens, such as change i<=10 to i<10 and to change i=1 to i=15 (if you changed i=15 the loop would not run at all because the value of i is already greater than 10 )

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

Here is boost-html that might help you

IndianaRonaldo commented: Thanks!! I checked out that one too, but it doesn't have very good forum support, so I went with libxml2. +0