Adak 419 Nearly a Posting Virtuoso

Welcome to the forum, Antichix! ;)

The way we roll here, is you get started on your program. Then, if and when you get stuck on something, you post up and we'll try to help.

We're SO not a "do your homework" or "get you started" kind of a forum. BTW, that's common among programming forums. Otherwise they're inundated by students who just want somebody to do their homework, for them.

So, take the lead, and report back if and when you're stuck. Post up at that time, what you've done, and be specific. Just saying "help" and nothing else, is not a good way to get good help.

Adak 419 Nearly a Posting Virtuoso

Narrow down what you're searching FOR: best routing? best move in a game? a string? a number? shortest path?

I don't believe downloading a search toolbox and displaying it's results, on some test data, is something that your instructor is going to be pleased with.

Adak 419 Nearly a Posting Virtuoso

I did some Googling, and there are some links to AES and Equivalent Inverse Cipher, but I haven't found anything that has a simple example or description of it.

It's all in Crypto-speak, so far! ;)

What have you found?

Adak 419 Nearly a Posting Virtuoso

You need to get this started. THEN if you have some specific questions, post up. Asking general questions before you get started, it sounds like you want somebody to do your assignment for you. You need to take the lead on this.

I know Wikipedia has a lot of info on string searching (and links as well). Google has a ton of links.

No, you get your own names or toolboxes. (I don't know of any toolboxes for this, btw.). Put some sweat into this!

Adak 419 Nearly a Posting Virtuoso

Hard to explain a crypto program in a forum post. This has a lot of info, a sample encrypt and decrypt function in C, and links to a lot more info on TEA.

http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm

Adak 419 Nearly a Posting Virtuoso

This is THE most complicated, and most verbose flood fill function, (because that's all it should be - one function), I've ever seen.

You've made a serious error in how you program:

1) You've written a lot of code, but obviously didn't do any testing along the way.

2) So the bugs are likely to be anywhere.

That's a very poor methodology. What you should have done is test each function as you went along, that it was accurate and kept the flow of the program, going as is needed.

The first thing I'd do if it were me, would be to goto Wikipedia and read up on "Flood Fill" algorithms. Then I'd choose one of those that I liked, and code it up. Check your compiler, also. It may have an extension expressly for this purpose. Note that flood fill may mean filling in just one color, or one area, and not the entire picture.

I don't want to sound negative, because the work that went into this is substantial. I don't understand WHY someone would do it this way.

Beyond accuracy and run time efficiency, one of the major goals of your programs is clarity. There WILL come a time that you'll want to adapt part of this code, for use in another program, or to extend what this program already does. See what I mean? Even if you get it to work fine, it's real value is greatly diminished.

Adak 419 Nearly a Posting Virtuoso

You need to process each keystroke from the player, quicker. Since you have conio.h, you should be able to use kbhit() to detect if a keystroke has been made.

Windows has it's own equivalent way to detect if a key has been pressed, and your program needs to use ONE (not both), of them, to stop the backup of the key strokes, in your snake game.

In this "inner loop", you can't have any buffered input to stop the unbuffered input, of course.

Adak 419 Nearly a Posting Virtuoso

fgets() is the more robust and generally better input function to use with the user.

In this case, and just as an alternative, a format specifier for scanf() might be used:

scanf("%[^\n]s", str2);
getchar(); //get rid of the newline char

Which tells scanf() to continue taking input until you hit the enter key ('\n' is the newline char you get whenever you hit the enter key).

and after that scanf(), use the getchar() to remove said newline from the keyboard buffer. (Which is THE biggest complaint for noobs in C)

I don't like scanf() for user input BUT it is used in all the classes and books, so ... and this is a very helpful format control for scanf().

Adak 419 Nearly a Posting Virtuoso

Well, I didn't know what the "AES" was, and now I've discovered "AES" is the Rajindal algorithm. I knew it as that before it was accepted by NIST, and became the new AES.

So, back to your problem. You're going about this the wrong way, my friend. You don't want to "roll your own" encryption algorithm, even if you have a certain pattern or knowledge about it. Even the pro's make mistakes designing their algorithms, and they're made useless by some attack or other.

The code you posted is just one part of an AES program. There is much more to it than this one for loop you have posted. Way more.

If you want to "roll your own" crypto program, I suggest "CipherSaber"
http://ciphersaber.gurus.org/

Which is vastly easier to program. Designed actually, to be easily remembered and mastered. No, it's not as good as AES, and for constant use, I don't even believe it's practical, because it has no way to use public keys readily.

If you want a stronger crypto algorithm, then find one of the posted AES programs, and copy and paste it.

Because what you have for code, is almost nothing, and these programs run into a few pages once you get some decent features into them. It's not easy code to write or understand, and they're a horror (of course), to debug. There's nothing here for the beginning student to easily work with.

I don't like …

Adak 419 Nearly a Posting Virtuoso

Do you need to put an end of string char into buff[0]? '\0'

Yes - even if you don't NEED to, you need to, ;) and I would. Just good defensive programming when dealing with different strings, going into the same variable.

Adak 419 Nearly a Posting Virtuoso

I'm just curious - what would you guess that "lib" is short for? ;)

I mean really, take a guess!

When you're ready for a bitchin' C IDE and compiler, FREE! and includes support for conio.h (like Turbo C), but works on 32 and 64 bit cpu's and OS's, like Windows XP, Windows 7, Windows Vista, and Linux:

Pelles C! IDE, HELP files, HELP forum, and no bloat! ;)

http://smorgasbordet.com/pellesc/

I'm been using Turbo C since ver. 1.01 (and still do for small puzzles and stuff), and disliked the horrid interface of MSVC and it's bloat. But Pelles C is WONDERFUL stuff.

You try this for 30 days, and I guarantee you will be glad you did.

jonsca commented: Make this a sticky!! +6
Adak 419 Nearly a Posting Virtuoso

To show shapes and ALWAYS to post code

<< Use [code] tags >>

Then the editor will retain ( more of less ;) ), the shape you want, AND the code will be shown in a font that's easy to study code with.

Click on the [code] icon in the editor, then paste your code. It will automatically put your cursor right between the tags, perfectly.

To draw triangles, general understanding is needed:

You have a max width (number of stars on the longest row).

The mid point of the triangle is (maxWidth/2 + 1) if the number of stars in max width is odd (should always be odd).

When you start the first row, you need to print 32 (space char), until you have counted out maxWidth/2 spaces, then print the * at the top of the pyramid.

Every row thereafter, you will print one fewer (generally) space char's, and two more stars (asterisks).

When you have printed maxWidth stars, you have printed the last row.

Use paper and pencil to work through this, until the light bulb goes off. When you really understand the problem, you'll be able to do pyramids of any orientation.

Adak 419 Nearly a Posting Virtuoso

What is the size of i in this code?

Why aren't you using a macro for you size of the array?

For static arrays:

#define SIZE 20  //note: no semi-colon on the end of this line!

int main(void) {
  char stringArray[SIZE][40];  //your array name, of course, not stringArray
  
  //your other code in here
  return 0;
}

Something like this ^^^^

Also, please post the struct declaration, so I can see what firstname really is.

Adak 419 Nearly a Posting Virtuoso

That's a very odd sort block of code. I'd dump it. Here's an easy one (this is substitution sort and should be used for small and medium sorting jobs).

Where SIZE is the size of the array with data you need sorted
where i and j are integers
where you have a 2D string array[SIZE][30]; //approx. on the 30
where you have a 1D char array[30]; //holds just one name at any time


for(i = 0;i < SIZE-1; i++) {
  for(j = i+1; j <SIZE; j++) {
    if((strcmp(array[i], array[j])) > 0) { //out of order?
      strcpy(temp, array[i]); //to temp
      strcpy(array[i], array[j]); //j to i
      strcpy(array[j], temp); //temp to j
    }
  }
}
printf("\nIn sorted order:\n");
for(i = 0; i < SIZE; i++) 
  printf("%s\n", array[i]);

This will sort according to the ASCII values (OK, the character set values you have on your system, but normally they're the same as ASCII values.

This is not exactly the same as a lexicographic sort (like the Dictionary). Close, but not quite the same.

Adak 419 Nearly a Posting Virtuoso

Can't help much with code, if I can't see it -- please post it, and please use [code]
tags around it.

Adak 419 Nearly a Posting Virtuoso

It's easier if you create the array in the calling function, then pass it into the called function as a parameter. Upon return from the called function, the array is still valid, and has the data you want in it.

You can do it the other way, but it's more work.

Splam Bub commented: Nice and helpful. +0
Adak 419 Nearly a Posting Virtuoso

You're welcome. ;)

Remember to use code tags, next time you post up code!

Adak 419 Nearly a Posting Virtuoso

Selection sort has nothing to recommend it, *except* it makes the absolute minimum number of comparisons. Other than those rare times that comparisons are inordinately costly, it's not a sort to use.

The fastest general purpose sort on Windows (since Windows 2000), is to use the system sort, with a command line on the terminal window:

sort <Unsorted.txt >Sorted.txt ( ;) )

Why? Because MS set aside special resources for sorting, that your program can't begin to match. I have several versions of Quicksort (optimized with Insertion sort for small sub arrays), Radix, Flash, Merge, Comb 11, etc., in C, and none of them come close to the system sort. And they never will. Easy squeezy also, since it does the merging of the temp files for you.

After that, in general, it's faster to sort in memory than on the HD (SSD might change this a bit). Sequentially reading the data, instead of bouncing the read head back and forth, is what you want here.

So, an array that is a multiple of 32 or 64 (depends on your OS size), and your drive's own buffer, is called for.

Fastest general purpose sorter I have is the tweaked Quicksort mentioned above. If you can get away with leaving the data unsorted, but making it appear as if it's sorted by using an index array, then use the index array method. Combine that with Quicksort, or your favorite fast sorter.**

Fill your array, …

-Powerslave- commented: Though this will be a zombie post, I'd disagree with you. User-to-system transitions are costly whch means you can create an even more optimized sorting code. Using the system is still right if getting the job done quickly has priority over performance. +0
Adak 419 Nearly a Posting Virtuoso

I'm intrigued, and finding the country would be easy, but the phrase "plain text substitution MOD 78" part, just won't let my head wrap around this problem.

There must be some little tidbit of info more -- c'mon, spill it!

<< bright light, 3rd degree regards >> ;)

Adak 419 Nearly a Posting Virtuoso

Sonuja, we aren't interested in "providing examples" and explanations for SQL access.

What we do is help you with your C code, if we can. You need to put in the work to first, get a start on your code. Then post it, and tell us what's gone wrong or what has you stumped.

There are a LOT of SQL access examples on Google, if you want to study them.

Adak 419 Nearly a Posting Virtuoso

This is the general idea, (from my first post):

char buffer[100]; //nice and big :)

fgets(buffer, sizeof(buffer), filePointer); //put the whole row into the buffer

if(first char in buffer is < '0' || the first char in buffer is > '9') 
   //It's a word or string of some kind
   //so handle that, here
else 
   sscanf(buffer, "%d", &number); //not a word, so get it into your number variable

Do you want JUST the names, or do you want the names and the ages, saved? One post says both, one post says just the names.

No, this is not like using strtok(), at all. It does get names (and ages if you want them), but it doesn't use the same logic as strtok().

Adak 419 Nearly a Posting Virtuoso

For encrypting, N would be a number that was defined or declared a const, earlier in the program. K I'm not sure of, but I'll hazard a guess it's a prime number chosen by the algorithm, on this run. Might be a hash value, also.

Key[] is the index array used to help encode (along with i and some simple arithmetic), the plain text (word[]), into encrypted text - which is being put into the array w[].

You need a bit more info on N and k, and on the values put into key[], before this while loop started.

What algorithm is this taken from?

This is not difficult code, but you need a bit more info to do it as it was intended to be done.

Adak 419 Nearly a Posting Virtuoso

Oh! Even easier, since all the tags begin with a double quote. Test for that double quote at buffer[0]. If you want the numbers as well, then use logic like my previous post has.

And don't worry about the rest of the char's that you don't want, being in the buffer. They will be over-written in the next call to fgets(), anyway.

Adak 419 Nearly a Posting Virtuoso

No worries, Nurkan. We just get a LOT of requests from students who want us to take their assignments, and do them for them.

Our second gripe, is with posters who put up code, but somehow, someway, don't see the [code] tag icon in the forum editor.

So their code looks like shit to study. Always use code tags when you post code. (Just click on the [code] icon in the editor, and then paste your code between the two tags it puts into your editing reply box). It really lets your code look good if you indent your code reasonably.

Adak 419 Nearly a Posting Virtuoso

If statements are needed because some comparisons involving the row of char's is needed.

There is a simple way, to do it though. (Loose code to emphasize logic)

char buffer[100]; //nice and big :)

fgets(buffer, sizeof(buffer), filePointer); //put the whole row into the buffer

if(first char in buffer is < '0' || the first char in buffer is > '9') 
   //It's a word or string of some kind
   //so handle that, here
else 
   sscanf(buffer, "%d", &number); //not a word, so get it into your number variable

That's one of the beauties about fgets(), btw. ;)

And welcome to the forum, Nadleeh! ;)

Adak 419 Nearly a Posting Virtuoso

The directory where the graphics driver is located. If you put these files into the current BIN directory, then just use an empty string there: ""

You should not have a $ in your parameter as you call initgraph(). That $ should be replaced with an ampersand: & instead.

Oh! You have the order wrong, also:

First parameter is: &gdriver
Second parameter is: &gmode
Third parameter is: pointer to driver path, if not in current directory

There is no dollar sign in any of these parameters, only two &'s for special characters.

Adak 419 Nearly a Posting Virtuoso

Welcome to the forum, Nurkan! ;)

The way it works here, is YOU need to show some work on this program, and post your code up. Tell us what is giving you problems.

Then we try to help.

We are not a "homework done for you", kind of forum.

Adak 419 Nearly a Posting Virtuoso

malloc(SizeOfArray) is part of stdlib.h, and allocates memory "as is", in the amount you request

calloc() is also part of stdlib.h, and allocates memory which has been set to zero or '\0'.

Both of these return a valid pointer to the allocated memory, if the request was performed, and NULL otherwise. (always good to test the return on these two functions).

For code snippets showing it, look for dynamic arrays in the forum searcher.

Adak 419 Nearly a Posting Virtuoso

You're looking at the same problem, from WAY different perspectives.

Narue has a lot of experience, at a high level, with languages, while VEGETA-DTX has very little experience, but STILL has a valid point to make.

As the old quip says: (and I roughly paraphrase)
"The great achievements of man have been realized because we had giants standing high on the shoulders of other giants.

Software advancements have been described as the achievements of midgets, standing on the toes of other midgets."

;) ;)

We are moving closer to a graphic programming ability, but it's not nearly as easy as you might naively suspect. We need to keep wanting it, to keep the motivation to move it forward, at a higher level, imo.

Personally, if I were going to work on a language, I'd love to work with Google on Go! I've been a big fan of Ken Thompson and his various projects, for a long time:
He helped design the language B, he built and programmed a chess playing machine that became world chess computer champ, (prior to Deep Blue), and now he's working on Go!
which has concurrency, garbage collection, wickedly fast compile times, and OK speed, as well.

Absolutely nothing graphical about it (very constrained formatting of code is required), but that's no problem for me.

I have high hopes for Go! ;)

Someday, there will be a graphical language, good enough for general purpose …

Adak 419 Nearly a Posting Virtuoso

main() is the point that the program jumps to when it starts running. It's like the starting line of a race.

While some races are handicapped and have more than one starting point, the computer is not so inclined.;)

As L7Sqr mentions above, there is nothing like a good test to see for yourself. Not only will you conclusively prove the answer on your compiler, but you will remember it far longer, because you learned it by trying it, yourself.

Adak 419 Nearly a Posting Virtuoso

Ancient Dragon already laid out how to read a file, if you want to read the entire file, row by row:

while( fgets(buf,sizeof(buf),in) // read the rest of the file
{
   //your other code in here, will strcpy() buff array
   //into another string or string array. First, you could
   //remove all the comma's in the string, very easily.
   //One of the beautiful things about using fgets().
}

You'll be doing yourself a favor to make a note of the above, and get really familiar with it. Very useful indeed.

I would use sscanf() to get the column you want's data, out of the row. I don't really prefer strtok(), for you, since it modifies the string, as it's working.

Look at that! I already gave you this same advice. :(

No offense, but you need to either work on reading or studying the replies you're being given, in the forum. You're wasting people's time, as it is. Here's my previous reply to you, in your other thread on this assignment:

make a char buff[100] array, to hold one line of text
make a float data[SIZE][COLS]; //fit your sizes for rows and columns.Leave room for 
end of string char and newline char, in your column number  
still have index[SIZE];

while((fgets(buff, sizeof(buff), filePointerName)) != NULL) {
  ok = sscanf(buff, "%*s %*s %f", floats[i]; //skip the 2 leading strings, store the float number into an array of floats
  if(ok > 0) {
    strcpy(data[i], buff);//copy buff string (including float), …
Adak 419 Nearly a Posting Virtuoso

VS has posted 13 times - past due for the OP to start using code tags.

Deducting rep points for using code tags, instead of the (more concise) icode tags, is a bit too much control, imo.

WaltP commented: Agreed. If you like CODE rather than ICODE, go for it... +15
Adak 419 Nearly a Posting Virtuoso

First, don't use feof() to test for the end of file - it doesn't work as you think, and you'll frequently get doubled last data.

Second, to ignore a row of test, just pull it into a variable that will be immediately overwritten, outside of the overall loop that you use to read the file with.

Adak 419 Nearly a Posting Virtuoso
he original file is like :

abc def 4.5 jkl mno
abc qwe 1.0 uio iop
def abc 3.6 iop nmb

should be like :

abc qwe 1.0 uio iop
def abc 3.6 iop nmb
abc def 4.5 jkl mno

then what changes do i need to make.?

One way to do it:

make a char buff[100] array, to hold one line of text
make a float data[SIZE][COLS]; //fit your sizes for rows and columns.Leave room for 
end of string char and newline char, in your column number  
still have index[SIZE];

while((fgets(buff, sizeof(buff), filePointerName)) != NULL) {
  ok = sscanf(buff, "%*s %*s %f", floats[i]; //skip the 2 leading strings, store the float number into an array of floats
  if(ok > 0) {
    strcpy(data[i], buff);//copy buff string (including float), into data[i]
    ++i;
  }
}

You'll be sorting ON the floats[] array, using the index[]. The index array will be sorted, using the floats[] numbers.

After the sorting, the entire string can be printed out, through the index array (as shown in my example program, but now you want to print out data[index] (the entire string from that row of data), instead of just the numbers, as I did, above.

Adak 419 Nearly a Posting Virtuoso

Morse code has no equation or algorithm to figure out it's series of dots and dashes.

It was made for brevity and ease of understanding, not computer algorithms, unfortunately for us. ;)

Adak 419 Nearly a Posting Virtuoso

It's hard to take your request seriously when you post up some code that won't even run.

There are lots of other posts on this subject, here and all over the net. Also, check out the Sieve of Eratosthenes, on Wikipedia, etc.

Come back with a full program, and then we'll talk turkey on your speed up. ;)

Adak 419 Nearly a Posting Virtuoso

Standard practice would be to sort such data through an index or pointer array. I'll describe how to use an index:

Make an int (unsigned long if needed), with at least as many elements as there are rows of data in the file to be sorted.

Now initialize the index[] (array), so each number, matches it's current position number, in the index[]:

for(i=0;i<SIZE;i++) //SIZE is the number of elements in the index[]
  index[i] = i;     //simple, no?

Now, you're ready to start sorting, but instead of sorting (comparing and moving) the actual data, you'll make both of these, by going through your index. If you haven't seen it before, it's a bit confusing.

<< NO data is moved, whatsoever >>

Upon completion (and it's fast), you can print out (on screen, or to file, etc.), all the rows, in sorted order.

You guessed it - by using the now sorted, index. Here's what the final print out to screen might look like:

for(i=0;i<SIZE;i++)
  printf("%5d   ", data[index[i]]);

This is an example of Insertion sort, using an index array:

/* Demonstrates Insertion Sort by using an index[] array.

   Status: OK 
   Adak December 20, 2010

   Requires a file named "soup.txt" with this format:
Tomato 2.28 245678
Broth  1.60 313926
Pea 2.35 455092
Stew 3.85 210420
Noodle 2.41 110288
Vegetable 2.33 699240
*/

#include <stdio.h>
#include <string.h>
#define SIZE 15

void sort(float num[], int lo, int hi);
 
int main() {
  int i,ok; 
  float num[SIZE];
  char str[25]; …
Adak 419 Nearly a Posting Virtuoso

Step through the code with a debugger, and watch the values of the variables, as they change. Use asserts and print statements as needed, to help you debug it.

This is not a "shades of grey" thing. If your function is wrong, then find the bug. Troubleshooting code is an essential skill for a programming student to develop. Nobody knows your code, better than you do.

Adak 419 Nearly a Posting Virtuoso

I have not used the AES cryptology program.

Adak 419 Nearly a Posting Virtuoso

ptr is being given a new address, in the assignment statement ptr=&val, in fn(). It no longer has anything to do with i.

Adak 419 Nearly a Posting Virtuoso

There might be a lot of info out there for Connect 4. For years, it was a competition game played between comp sci students in college.

In fact, and this may blow your mind but it's true. A guy named Fabien L developed one of the top C4 programs. Later, he used his mad skills, to write a chess program called "Fruit". By version 2.1, it was kicking most of the top chess programs arses. Today, it still serves as the basis for many of the top chess programs, including Rybka, Houdini, and others.

Most of the chess authors thought "he must have used someone else's code, it's a rip off", because they had never heard of anyone writing such a strong chess program, in such a short amount of time. But it was all due to his years of competing in C4 contests, and he got a bit lucky, no doubt.

As I understand it, you can use either message queues or pipes to communicate from one thread to the other, but I have no expertise in this area. Lots of info on line about this.

If I had to get an answer to something like this (after Googling and etc.), I'd check out www.talkchess.com/ because all the chess program authors are going "Deep" (using multiple threads, etc). This is where the top chess authors on the planet get together and argue. ;) Including Fabien L. Bob Hyatt, Gerd Isenberg, and many other …

Adak 419 Nearly a Posting Virtuoso

I used a char array
char filename, and a char *extension = ".txt".

I used an unsigned int for the number. As the program looped around for another filename increment, the file_num++, of course.

iota() from ctype.h, was then used to put the number into the filename char array. Then I used strcat() from string.h, to add the .txt onto the end of the filename array. You need to include both ctype.h and string.h.


FILE *fp = fopen(filename, "wt");
if(fp==NULL) {
  printf("Error opening %s\n", filename);
  exit() or return;
}

If you don't have itoa(), check your help files for things like ltoa() or stroi, etc. You can "peel" off the digits from the number and put them into the string by hand, but it's much more work.

Post up your attempt and we'll get you sorted out.


Edit: For a small number of numbered files, only:

Char's are just numbers with a very small range, so you can also increment the filename char's, directly:
filename[3]++; //etc.


The problem with this, is you have to handle every bit of the arithmetic, yourself (changing a 9 to a 10, leaving the zero there, and incrementing the adjacent element of the array, by one). If you have many numbers, forget this and use the way above.

Adak 419 Nearly a Posting Virtuoso

Break it down into a few big steps (amid smaller one's):

1) Get your connect 4 program using one thread, working PERFECTLY. No crashes, no illegal moves, etc.

It's difficult to debug a multi-threaded program, so get the single threaded version of your code, working really spot on.

2) Now work your single-threaded code, into a multi-threaded program. Imo, let every thread work independently of the other, as much as possible.

3) Now polish it up, and test it out, REALLY well. You may find bugs long after you thought they were all gone.

There is all kinds of example code for both multi-threading and connect 4 on the net, so get in there and study up. This will take more time than you expect, so don't put it off.

Adak 419 Nearly a Posting Virtuoso

There were three bugs:

1) Gerard found the big bug, which was the improper initialization of the array values.

2) The index out of range bug

and

3) The < operator needed to be changed to > if you wanted the largest number in the array.

The #2 error was not causing a run-time problem, but you see this all the time with C programs. The pointer or index for the array, goes out of bounds.

Asserts can help keep that down, but everyone should know that special care must be taken to test that the index referencing the array, must be carefully tested at the low and the high ends of the array range, for this type of error.

Adak 419 Nearly a Posting Virtuoso

Sorry, mkab. That won't work.

j+1 is the standard C idiom used in bubble sort, and all kinds of other algorithms that check adjacent elements in an array.

if SIZE = size of the array, then

j = 0; j < SIZE; j++ is simply wrong.
j = 0; j < SIZE - 1; j++, then array[j] can be correctly compared with array[j+1]

Any reference to array is an error, in C, and no logic exists that will make it correct.

Yes, his program may run right, since errors in C do not guarantee a program will crash. It may even run correctly, for a long time (in some cases, the bug is never detected).

With a larger array, I believe I could crash his program in a heartbeat, but that's irrelevant. We want the logic to be correct.

Adak 419 Nearly a Posting Virtuoso

My eyeballs get tired just studying your code. ;)

Instead of two arrays to convert letters from one case to the other, why not use toupper() or tolower() (part of ctype.h)? Another easy way would be to simply use the ascii values. Since there is a constant difference of 32 between the uppercase letter and it's lowercase equivalent, we can use:

ch += 32; //to change char ch from uppercase to lowercase
ch -= 32; //lowercase to uppercase

Both the above work ONLY for letters, and ONLY if your system uses ASCII or other character values with this 32 offset (most do). Try it on your system.

You're using u and y for for loop iterators - please don't. Use the standard idiom of i and j and k if you need it. When you have no comments in your code, it's just so much easier if you use standard C idiom's.

You should be using strtoi, atoi or sscanf() to take your string digits, and convert them into a (real) number. It's so easy.

I'm all for repentance from sin, but go to confession, instead of beating yourself up with C. ;)

Be as simple and concise and as clear, as you can be in your algorithm and code. You'll be glad you did.

Edit: set your editor up to insert 3-5 spaces, instead of full tabs, when you hit the tab key. Your indentation is so great, that your …

zetologos commented: thanks for useful advice +1
Adak 419 Nearly a Posting Virtuoso

You're letting j run outside the boundary of the array on the last loop.

Keep it < 5, always. Also, < should be > in your comparison, if you want the largest number. Otherwise, you'll get the smallest number in the array.

Adak 419 Nearly a Posting Virtuoso

To fill the array with unique int's from 1 to 52, just use:

for(i=0;i<52;i++)
  array[i] = i+1;

Then you can swap random indeces around, until it's all shuffled

for(i=0;i<someNumberAtLeast25;i++) {
  temp = array[randomInt];
  array[randomInt] = array[randomInt2];
  array[randomInt2] = temp;
}

Give that a try. ;)

Adak 419 Nearly a Posting Virtuoso

Clocks aren't as easy as they look. For instance, Sleep(N) gives you AT LEAST N periods of time - but note the "at least" part of that. ;)

Because other programs and lots of Windows services (programs without a terminal window for output), are running, many times you'll get more sleep time than you bargained for.

Also, you have left zero time for your program to actually run - agreed it won't need much, but surely it will need some time.

So, what to do? One way is to subtract the amount of time you get back from the system, from either a minute, or the amount that you asked for. Then adjust how much time you ask for on the next loop, to account for it (basically, subtract it).

You ask for 60 seconds, and you got 60.5 seconds. So you ask for 59.5 seconds, on your next loop. You asked for 59.5 seconds, but you got 59.7 seconds. You ask for 59.8 seconds on your next loop (because it was .2 seconds behind what you asked for last time). And continue with that type of "carry over" logic.

Adak 419 Nearly a Posting Virtuoso

First suggestion is to Google for a C program called "Matrix". it uses this technique to simulate the graphics of the Matrix movie (falling chars), in the console window of your VDU.

It uses pointer notation, but remember that this: *(myArray + i) is the same as myArray, so therefore *(myArray +(numberOfColumn* rowNumber) + column), is the same thing as myArray[row][col].