Adak 419 Nearly a Posting Virtuoso

Think of an old fashioned car odometer, with three wheels displaying their digit.

Now use three nested for loops, and don't over-complicate it. Let the loops do their magic. No if's, no else's, no bs. Easy as pie. ;)

int w1, w2, w3;  //wheel 1, wheel 2, wheel 3

for(w1=1;w1<10;w1++) {
  for(w2=1;w2<10;w2++) {
    for(w3=1;w3<10;w3++) {
      printf(\n %d %d %d", w1, w2, w3);
    }
  }
}

Try that, see if you understand it.

Adak 419 Nearly a Posting Virtuoso

The number of iterations needed to sort, will vary considerably depending on the number of items there are to sort, as well as the algorithm you choose.

Even a non-comparison sorting algorithm like Counting Sort, will have to iterate through once, for each item to be sorted.

It's very instructive to count them up, for say 25 or 100 items. You'll be surprised at the variances between algorithms, in iterations, comparisons made, and swaps made.

Adak 419 Nearly a Posting Virtuoso

Why aren't you including math.h?

Looks like an overflow problem, at first glance.

Adak 419 Nearly a Posting Virtuoso

This isn't a project idea forum, but there is a lot of material on the web on this topic.

Google my friend, the sooner the better.

Adak 419 Nearly a Posting Virtuoso

Yes, the switch/flag idea works.

Adak 419 Nearly a Posting Virtuoso

This is the program:

#include <stdio.h>

int main() {
  int i, j, k, temp, alpha1, odd1, even1; 
  char alpha[]="abcdef";
  char even[]="02468";
  char odd[]="13579";

  printf("\nThree Groups:\n %s <==alpha\n %s  <==odd\n %s  <==even",\
   alpha, odd, even );
  printf("\n\n Enter the number of items to be shown from alpha group: ");
  scanf("%d", &alpha1);
  getchar();
  printf("\n Enter the number of items to be shown from the even group: ");
  scanf("%d", &even1);
  getchar();
  printf("\n Enter the number of items to be shown from the odd group: ");
  scanf("%d", &odd1);
  getchar();
  printf("\n One Two Three:\n==============");
  for(i=0;i<alpha1;i++) {
    //printf("%3c", alpha[i]);
    
    for(j=0;j<even1;j++) {
      //printf("\t\t%3c", even[j]);
      
      for(k=0;k<odd1;k++) {
        printf("\n%3c %3c %3c", alpha[i], even[j], odd[k]);

      }
    }
  }
  printf("\n\n\t\t\t     press enter when ready");

  i = getchar(); ++i;
  return 0;
}

I was wondering if some boolean type switches or flags could be added to control the printing of the wheels, according to the requirements of the assignment.

Adak 419 Nearly a Posting Virtuoso

Remove the first ++ from howlong++.

getch() returns it's value to the left hand side (the Lvalue), of the equation:

char1 = getch();
if(char1== 'p')
  break;

Would be how I'd do it. But there's another problem which is always present when scanf() is involved (potentially), and that is clearing out the newline char after the scanf(), prior to the scanf() for a char.

numbers are not bad, since scanf() will skip over a newline, but scanf() can't possibly skip over a newline when it's there to get a char - and this may be your real problem.

So add a getchar() just before the scanf() for the char, and see if that helps. This is UNDOUBTEDLY the most asked topic on the C forums, for beginners.

Since you can't see the newline on the keyboard buffer, it's a shock for C students to learn that scanf() leaves the newline in the kb buffer, and it causes problems, if you don't pull it off, (getchar() is one good way).

overall, don't get too addicted to scanf(). It's too "brittle" for user's to be trusted with.

Adak 419 Nearly a Posting Virtuoso

I would suggest if(row < 1) and if(col < 1), rather than < 0. Our arrays start with zero, but that is the first row, so the array has to have at least 1 row, and 1 column, also.

Think about that data entry loop. If I say I want 2 rows with 5 columns each, why would you want a loop asking for values up to SIZE (100)?

Before you enter any values, you need to malloc() memory for the array!

In your print function, you need to remove the ampersand '&' from &array[k], and in the scanf()'s you need to add the ampersand in front of array[j]

An array is a matrix - if you mean from a 1D array to a 2D matrix (with rows and columns), that is done when you malloc the memory.

In main, row and col should be int's, not int pointers, unless your assignment requires it. When other functions need to modify the row or col number in main, then they should be passed the address of row or col, and receive it as a pointer, in the called function.

Adak 419 Nearly a Posting Virtuoso

OK, this is one way I was looking at it. I did this with arrays, BUT there's no reason why the array could not be replaced (index by the depth of the linked list).

Three groups, with my choices being to show 3 values from group1 (Alpha), 3 values from group2 (even), and 1 value from group3 (odd).

Output is:

abcdef <= alpha group
02468  <= even group
13579  <= odd group

 Enter the number of items to be shown from alpha group: 3
 Enter the number of items to be shown from the even group: 3
 Enter the number of items to be shown from the odd group: 1


groups:
  One Two Three (alpha, even, odd)
================
  a   0   1
  a   2   1
  a   4   1
  b   0   1
  b   2   1
  b   4   1
  c   0   1
  c   2   1
  c   4   1

			     press enter when ready

Is that somewhat close to what you want for output of your program?

Adak 419 Nearly a Posting Virtuoso

see. I thought you were just being ornery.

My idea was to use small separate arrays, one for each group.

If you have experience working with an array of linked lists, you're programming skill is beyond mine. I've never worked with such an array, nor have I seen code for such, although of course, I know they are used.

I will think on your problem.

Adak 419 Nearly a Posting Virtuoso

fgets() gets a string (a row of text), at a time, from a stream (a file in this case, but it could be from the keyboard using the stream "stdin"). Input stops when either the size of input you specify is exceeded, or there is a newline char found, indicating the end of a line, in the stream's content.

fgets() will add an end of string char: '\0' to the end of the string. Also, it will put the newline char: '\n' next to the end of the string, like this:

my input string data\n\0

The best thing about it is that it will take an entire line of text at one time with no problems about spaces, punctuation, etc. and it never will overfill the buffer you have set up for it. (If pinched for room, it will leave out the end of string char, but avoid that happening, you want that end of string char on there.)

buff1 is the name of the buffer, but also serves as a (constant) pointer to the address of the base of the buffer., sizeof() gives the size of the data structure, and f1 is the file Pointer.

sscanf() is the cousin to regular scanf(), except you pass it the name of the string to scan, and it scans there, instead of from the keyboard. That's why it has that extra 'buff1" name in there.

You're very welcome. ;)

Adak 419 Nearly a Posting Virtuoso

I've seen code for this (what language I'm not sure), last year, when I was doing some looking around on google for Permutations and combinations.

I can't imagine why you'd want to build a data structure, before you had an algorithm. Or why you'd want to use an array of lists.

I guess you know what you're doing - good luck.

Adak 419 Nearly a Posting Virtuoso

This is your program, with a few twists to show how I'd do it, with the new format you have mentioned.

It's inefficient because the data files are not in sorted order. For small amounts of data, it's OK, however.

#include <string.h>
#include <stdio.h>

int main() {
  char buff1[4]; 
  char buff2[256];
  char name[30];
  FILE *f1;
  FILE *f2;
  int num1, num2;
  f1 = fopen("1.txt", "rt");
  f2 = fopen("22.txt","rt");

  printf("\n\n\n");
  while((fgets(buff1, sizeof(buff1),f1)) !=NULL) {
    sscanf(buff1, "%d", &num1);
    while((fgets(buff2, sizeof(buff2), f2))!=NULL){
      sscanf(buff2, "%d %s", &num2, name);    
      if(num1==num2) {
        printf("\nFound a matching number %d. Name is %s", num1, name );
        break;
      }
    }
    rewind(f2);      //reset f2 to the start of the file
    buff1[0]='\0';   //reset all three buffers
    buff2[0]='\0';
    name[0]='\0';
  }  
  fclose(f1);
  fclose(f2);
  getch();
  return 0;
}

Note that the fopen() lines of code, should be followed by a test to see if either pointer is NULL. If so, the program should terminate quickly with a return 1 statement.

Whenever your program opens files, test that they have indeed been opened.

Adak 419 Nearly a Posting Virtuoso

These aren't things you can google really. That's why I wrote "post back if you get lost".

In your first post you mentioned a "number.txt" file. Now you're indicating a 1.txt and a 22.txt file. Which leaves me confused on that point.

Is 1.txt the number file now, and 22.txt is the name and number file, maybe?

Can you make a 5 line number file, and then do the same with the name and number file, right down to the file names each one will have. Because all the details here, are what is lacking for a good solution. Do you want to open every file that has a number in the number file?

And then what should the program do once the right file is opened?

It's not hard to do this, but each detail has to be in place.

Adak 419 Nearly a Posting Virtuoso

Post back if you get lost in my description, Itsmeisuru. Sometimes when I get into describing a solution, my writing ability goes sideways and hits the guard rails. ;)

Adak 419 Nearly a Posting Virtuoso

Whatever the constraints are, they'll have to have logic to handle it. Nothing magical about nested for loops, they're just a good simple way, to handle creating combinations.

The more difficult the problem, the more likely the logic will need to move to a more representative design, and at the same time, have more low level variables.

Basically, although the nested loop is there, it doesn't mean it has to be entered into, (looped through), for any combination. The logic has to determine which for loops will have their loop bodies executed.

Your solution idea may be better than mine, Abhimanipal. I am hoping that the OP will look back in his class notes or book, and see what it is that the instructor wants him to use, in this case. Seems like a very difficult problem to just toss out to a student, without some lecture or written assistance.

Adak 419 Nearly a Posting Virtuoso

OK. First, open the number file, then open the number and name file. Here, use fgets(), to put the whole row at a time, into a char buffer array.

Include string.h to allow:
len=strlen(buff), after you've fgets() a row of text from the name and number file.

Then your buffer will look like this:

name4\n\0, with the last two char's not being visible, but they'll be there. So we're going to trim them off:

buff[len]-2 will be the number you want. We're repeat this for every row of text in the name and number file, until either we find the right number, or the file runs out of data for us.

If you'll post up a bit of code, and tell us where you're stumped with this, we can be more helpful.

Adak 419 Nearly a Posting Virtuoso

The data type is irrelevant. You can do what I suggested with any data type. It's a matter of logic.

1) You can't have s[1] = 1, 2, 8, etc. s[1] is the element in s[] right next to s[0] and s[2], and can hold just one integer, not five.

You could call the arrays s1[], s2[], and s3[] however. That would be fine.

2) You need the include file stdio.h. You don't need a node or a struct, so you can delete them.

You need a main(), and the the three nested for loops - one for each "wheel". (data set)

3) Always use the code tags around your program on the forum. Otherwise, the program gets smashed over to the left hand side, in a very bad font to study, like it's html text. Just click on the [code] icon at the top of the advanced editor window, and then paste your code between those provided tags.

If you think it won't work, consider that your car's odometer displays every single possible mile combination: thousands, hundreds, tens, ones and tenths, on your car. That's all we're doing here - building a virtual odometer, but we're changing the digits to be the numbers in the set that that wheel, is representing.

Adak 419 Nearly a Posting Virtuoso

That's not a logical problem - think of your odometer wheels again. Imagine that instead of each wheel having 10 digits (0-9), that the right most wheel of the three (which is the one I use as the "driver" wheel), has only two digits, 1 and 2. And the middle wheel has but a single digit: 1, while the left most wheel (the A set), has 3 digits: 1,2,3.

Use you nested for loops again, but you don't need a for loop for the middle wheel, because it only has one value. So you're down to an ez two for loops.

I've used this several times, it works just fine. If you set the wheels up with their arrays being sorted to start with, and having their start values be the lowest value possible, then the output will be in sorted order.

Note that a1, b1, c1 is repeated in your post. That indicates a refinement of logic is needed in your loops. After the c wheel has generated c2, the next increment for it should be back to c1, and the a wheel should be advanced to the next value.

Adak 419 Nearly a Posting Virtuoso

Think of it like three wheels on an old fashioned car odometer. Each wheel is from a different group, and each wheel can spin around, and then go back to it's starting value.

Three nested for loops is the simplest implementation I know. Arrays are what I use, for each group. Any data structure should be OK, but I like arrays for their simplicity and speed.

To see every possible combination, just have the right most wheel as your "driver" wheel, and when it has gone through all it's possible values, then it "kicks" the wheel immediately to it's left, over by one value. Just like a real odometer worked.

Adak 419 Nearly a Posting Virtuoso

A very simple function. Here's a sample program:

#include <stdio.h>
#include <string.h>

int main() {
  int i, j, temp; 
  char s[]="Once a jolly swagman";
  i=0;
  j=strlen(s) - 1;  

  while(i < j) {
    temp = s[i];
    s[i++] = s[j];
    s[j--] = temp;
  }
  printf("\n\n New string is: %s", s);

  printf("\n\n\t\t\t     press enter when ready");
  i = getchar();
  return 0;
}
Adak 419 Nearly a Posting Virtuoso

Have you tried testing the return from sscanf() ?

When it return anything less than 1, you should be at the end of the file - or at least something stopped sscanf() from working right.

It is frustrating how you have to "dance around" to do such a simple thing.

creeps commented: I love to hate the last sentence :) +1
Adak 419 Nearly a Posting Virtuoso

Creeps got your back, Nigel. while(variable > 0), peel those bad digits right on off.

Adak 419 Nearly a Posting Virtuoso

I have a better idea: You read the Wikipedia article on Sieve of Eratosthenes, and get started on implementing that algorithm, into your program.

Then you post it, when and if you get stuck or have questions - and we will strive to help out.

Because we're not a homework service, and nothing helps your learning more than having you actively engaged in the whole learning process.

And welcome to the forum!

Adak 419 Nearly a Posting Virtuoso

No, you can't get access to the cpu clock, or run DOS on a Windows XP or above. The Windows kernel was changed with Windows2000 to the NT version. Now, DOS programs can run only in a virtual window of some kind. NTDVM.exe is the one I see in WindowsXP all the time. (NT kernel DOS Virtual Machine). VMWare and DOSBOX can do the same thing for you.

If I were doing something that required critical timing, I would buy a clock board. Haven't priced them in a long time, but they weren't very expensive back in the day, so they shouldn't be too costly.

Some boards, and some versions of Windows do have better than the old PIC (programmable interrupt controller) based timing, but it's hit or miss, imo. With a clock board and a minimum number of services and other programs running, you have the best chance of getting reliable timing info.

You can't get good timing info from your oscilloscope?

Adak 419 Nearly a Posting Virtuoso

Welcome to the forum, Reliableravi. ;)

Post up a line of text that you typically want the program to find, and then show (and hopefully tell us), what you want done with the output of the program.

And I KNOW you will post up your attempt to program this in C. That's how this forum works - you post up your attempt, and we help you make it right or better, if we can.

But we're not a homework or programming free service.

Adak 419 Nearly a Posting Virtuoso

You're trying to malloc() memory, but haven't included the required stdlib.h file.

Normally, you'd get an error message, but since you're also casting the results of malloc() in your program, that error is not sent.

Malloc returns a void pointer, so there are very few times that you need to cast it - it's handled automatically.

Adak 419 Nearly a Posting Virtuoso

static variables are initialized just once, on the first call to the function.

There was a need for a static variable that would be encapsulated (could be used) by a certain function, and no others.

If you have a particular question about your program's storage classes, post up the code, and ask away.

It doesn't make sense to make a rather long tutorial about a general topic in a forum - it just gets moved off into the archives far too quickly, and then gone.

There are a number of good tutorials available on the net, some are even video's about C, from major colleges and universities. Why not Google them up and view a few?

Adak 419 Nearly a Posting Virtuoso

If a program that compiles and runs, doesn't give the right answer, I put everything up as a suspect. Naturally, you want to prioritize the suspect list for checking, and logic errors are far more common, but "always" things, still make the bottom of my "to be checked" list.

You might think my list is nit-picking, but I can assure you, my programs have no lice! ;)

Adak 419 Nearly a Posting Virtuoso

You have three needles, so you need three stacks.

Push each disk's value (way I did it was to have the value equal the width of the disk), onto one stack. Let's say you had 3 disks to be moved, and all the disks had to end up on needle #3, after starting out on #1 needle.

The moves would be:


1) 1 - 3 (because you have an odd number of disks to be moved from this needle)
2) 1 - 2 (because now you have an even number "" "" "" "" "" "" "".
3) 3 - 2 clearing the needle #3
4) 1 - 3 Back to an odd number - so move to the final goal needle
5) 2 - 1 There are an even number on this needle, so move away
6) 2 - 3 Odd
7) 1 - 3 Odd

Done! ;)

Adak 419 Nearly a Posting Virtuoso

Two things:

1) If your compiler is Turbo C, you won't load the floating point package you need, with that code. You need to have at least one of the doubles assigned an initial value of 0.0.

(since TC's float package can be stubborn about this, post back if you're still stuck and I'll give you some code guaranteed to force it to be loaded. The above should do it, however.)

2) pow() expects two doubles as parameters. You're giving it one double, and one integer, instead. Whether that works or not, depends on the relative sizes of integers and doubles, and your compiler design.

See if the above solves your problem.

Adak 419 Nearly a Posting Virtuoso

Whether you use 3 linked lists, 3 small arrays, or 3 small LIFO stacks (I refer to FIFO structs as queues), just remember that if you want to move an odd number of disks to needle #1, then you start by moving the first disk TO needle #1. When you have an even number of disks, move the first disk AWAY from needle #1.

Since the computer can make the moves for the game so fast, it's great if you'd add a delay midway through the move of each disk - I put mine right at the very top of the needle the disk was being removed from.

It's extra work, but you can make a very colorful Tower of Hanoi game, using just the text console. Making each disk with it's own color, is a great improvement in the looks of the game, imo.

Note that the player should not be selecting a disk number to move. The player selects the *needle* number that he wants to remove a disk from - and only the top disk can be moved.

Adak 419 Nearly a Posting Virtuoso

Why the one char strings in refs[], instead of just single char's? Looks quite odd.

Adak 419 Nearly a Posting Virtuoso

I didn't doubt it, but I'm not sure just WHAT baby_c is using right now. She mentioned "C-free", and having gcc on another system. I don't know WHAT "C-free" offers for long long's.

On my 16 bit Turbo C, I have type long double, which is able to deal with it, but it takes some tweaking to be sure you have gotten past the float issues (where the number is not perfectly represented by the double, but it's oh-so-close).

Adak 419 Nearly a Posting Virtuoso

If your Borland is like my Turbo C from Borland, then you can't do it. I don't care how many data structs you use. You don't get more memory because you use more data structures. ;)

Global memory comes off the stack, generally. That is limited. Try the heap, it's bigger. (malloc uses the heap for it's memory source, not the stack)

The way to go with it, is to use a newer compiler. MS Visual Express, Pelles C, gcc, Code::Blocks with MingGW, are all compiler's that will allow you to enjoy larger memory access.

I love Turbo C, but for large amounts of memory - phffffftttt! :(

This is the program I wrote to test it:

/* Tries to load all 54,000 names from the names54k.txt file, into an
   array of pointers, where the memory for each name, is malloc'd.

  This was done on Turbo C, ver.1.01
*/

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

#define SIZE 4000
/* SIZE will vary depending on the length of the words
   that are being saved, from the file.
*/

int main() {
  unsigned int i, j, n; 
  int len;
  char *pstr[SIZE];
  char buff[40]="";
  FILE *fp;

  printf("\n\n");
  fp=fopen("names54k.txt", "rt");
  if(fp==NULL) {
    printf("\nError opening names file");
    return 1;
  }
  i=0;
  while(fgets(buff, sizeof(buff), fp)) {
    len=strlen(buff);
    if(buff[len - 1]=='\n')
      buff[len-1]='\0';
    
    if((pstr[i]=malloc(len))==NULL) {
      printf("\nError allocating memory: i==%u", i);
      return 1;
    }
    for(j=0;j<len;j++)
      *(pstr[i]+j)=buff[j];

    buff[0]='\0';
    ++i;
    if(i>SIZE) break;
    printf("\n%s", pstr[j]);
  }
  //for(j=0;j<20;j++)  printf("\n%s", pstr[j]);

  fclose(fp);
  for(j=0;j<=i;j++)
    free(pstr[j]);
  printf("\n\n\t\t\t     press enter when ready"); …
Adak 419 Nearly a Posting Virtuoso

We both did.

After I fire up the Turbo C IDE, I show just 403K available - yeeeee! ;)

Adak 419 Nearly a Posting Virtuoso

fmod(double, double), is being given a long as the second parameter in your code - so I don't know if it will work or not.

Adak 419 Nearly a Posting Virtuoso

So line 34 should have the 775,146 number, and the fmod() number should be the big 'un.

Did you get fmod() to work OK, with the big Number?

Adak 419 Nearly a Posting Virtuoso

Oh, I know it well.

I put that up to help the OP see that he can't store 54k names in ANY internal data structure, if he's using turbo C. Not gonna happen. ;)

That leaves the viable options external storage, only.

Adak 419 Nearly a Posting Virtuoso

Where did you get the 4559877 number? That's way big!

Correct is sqrt() of bigNum or 775,146 (and the decimal places thereafter you can forget about).

** I'm talking about line #34 in your program, not the fmod() line of code. **

Windows calculator will handle and confirm the above number.

Did you try the suffix ULL in gcc or C-free, for unsigned long long int's, yet?

Sree ec says they work in gcc for both 32 and 64 bit versions.

Adak 419 Nearly a Posting Virtuoso

You want to use a static char array or a dynamic array of char pointers? What do you think, maybe 50 rows, 80 char's each should be enough?

Adak 419 Nearly a Posting Virtuoso

I just tried this for fun in Turbo C, using an array of char pointers:

char *names[SIZE];

then getting the length of each name, and malloc'ing the memory for it, and putting it into the names[i++] position.

Using short names, TC was limited to less than 5k names (4,200 average).

Which means if the OP is trying to do this with TC, no matter what data structure you choose, if it's internal, you won't be successful.

Which bring me back to Creeps suggestion of simply keeping the names on a HD.
Although HD's can keep a lot of data in their cache, a better idea would be to use a virtual drive, in memory. Like a RAM disk file. I used one of these last year to avoid disk trashing while running a big project, and it worked out very well.

It is a shame to keep using a 16 bit compiler for work like this, when you have a 32 or 64 bit OS, with Gigs of RAM available, however.

Adak 419 Nearly a Posting Virtuoso

Remember the number line for bianry:

2^7  2^6  2^5  2^4  2^3  2^2  2^1  2^0

And our number line works the exact same way, just substitute a 10 for the left 2's, above (left hand side only in the case of 2^2, of course).

So that indicates that we can, in a loop, find the greatest power of the base (be it 2 or to), to begin "decomposing" any number.

Then subtracting that amount from the original number, we loop back, and look for the next largest value of the base ^the exponent.

It might help you to look at char's: What is their greatest value? What does sizeof(char) tell you about their size, in bytes?

How does their size, reflect on their maximum value?

What is a char's max value on your system? You can look for "limits.h", and the macro MAX_CHAR or CHAR_MAX, but you can also just:

char i=0;

while(++i > 0);
printf(%d", i-1);

print that out on paper in binary, and see how it looks. Print out the same using the sizeof(char), where each bit of the byte, has the value 1.

What do you notice? ;)

Adak 419 Nearly a Posting Virtuoso

Basically, they're like shit - they happen. ;)

You can roughly divide them up as compiler errors, compiler warnings, linker errors, logic errors, and run time errors.

Each one you could write a good deal about. For more info, Google each of the above, and check out some C tutorials while you're at it.

Adak 419 Nearly a Posting Virtuoso

What about using a binary search pattern on the addresses of the shorter link? (same size links, then choose either one). If at a given node the addresses are == then lo moves up to current position + 1. Next comparison would be 1/2 that far up the link. If not equal addresses are found, then move the hi marker, down, etc.

And instead of putting all the node addresses into an array, leaving them alone, and working with the sizeof(node) as the smallest increment/decrement size for the search?

Should bring it down to O(log N) on average. Maybe.

Adak 419 Nearly a Posting Virtuoso

I made that request

Did you try using "long long int" and "unsigned long long int"?

but she replied that it made no difference. She's using the "C-free" compiler, which may not support "long long int".

I don't know if she tried appending the "ULL" onto the end of the bigNum variable, however. Good point!

I found a way to work with this large number, in Turbo C, but she is still having some difficulty, at last report.

You are more than welcome to join in - it's problem solving, and should be from multiple sources.

Please don't post the code if you have made it already. It's like a Snipe hunt - you remember them your whole life, because they were so very hard to catch! ;)

Adak 419 Nearly a Posting Virtuoso

Turbo C is a 16 bit based product. To run it in Windows 7, you need a 16 bit (DOS sized), environment.

The easiest way to do this (afaik), is to use a program like DOSBOX or VMWare. Either one (get the right product from VMWare, as they have several), will create a virtual machine for your TC program to run in.

You may be able to set up Windows 7 to work with TC, but I'm not aware of just how that would work. By all means, check via Google, and Windows 7 forums.

If you have the option to do so, now might be a great time to update to one of the newer C compilers. Some are free, also, and do offer more features.

Adak 419 Nearly a Posting Virtuoso

Post up your code, and I'll see what's up with it. I've run it through with the big number about 50 times now, with no problem.

You have the big number assigned to a long double? And your printing it with %Lf, instead of just %lf?

Adak 419 Nearly a Posting Virtuoso

It would have been rather difficult.

However, since then, I have found a fun little scamp called fmod(). fmod() is in math.h (so include it if you haven't already), and what it does is give you the modulo (remainder) for the two doubles that you give it:

result=fmod(double, double);

So with that help, it became very easy to cast my unsigned long int I had found was a prime number, already, into a long double like bigNum, and have it tell me when the two were zero - that is, when the prime number I'd just found, was a factor of bigNum.

Oh yeah! ;)

so first, get the prime number
then result=fmod(bigNum, primeNumber)
if(result equals zero)

  • then primeNumber is a factor
  • save it as the biggest factor so far, if you're
  • genererating prime's from small to large.

end of if

print up your summary and the biggest prime factor.

Check out fmod() and see if it's included in your compiler's functions.

Adak 419 Nearly a Posting Virtuoso

If it involves C++ code or assignment, then you should post this request for help in the C++ forum, of course.

If it's for C code, you'll have to tell us about your project. What's the input, the computations you need to make, and the output?

Any other requirements, like complexity or specified algorithm, or formatting for the output, etc.?