Adak 419 Nearly a Posting Virtuoso

No nested for loop is needed for figure 1-4. There is a way to do this with nested for loops, but why use more loops, if it doesn't help make the code simpler, faster, or more intuitive?

You need 1 for loop, which counts from 0 up to the largest number of *'s in any of your rows. That's number 3) in my post, above. (This is true for figures 1,2,3 and 4, but not 5 or 6).

Inside that loop, you need an if statement to tell your program whether it should print a space or a *, on this time through the loop.

And that's all you need for figure 1,2,3, and 4. For figure 5 and 6, you need to:

1) print half of the spaces you calculate should be printed for that row
2) print the *'s
3) print a newline - you don't actually have to print the other half of the spaces

Adak 419 Nearly a Posting Virtuoso

Let's look at figure 3:

*
   **
  ***
 ****
*****

And let's say we have no left side margin, so the * that's closest to the left side, is actually all the way to to the left side.

How would you make this by hand? Probably, you'd say "I've got to have a maximum of 5 *'s, so what I'll do for the first row is press the space bar 4 times, and then print one *.

So mathematically you're saying:
NumberOfSpaces = (Greatest number of *'s in any row - number of *'s in this row.)

Which in this case, (5 *'s), means:

spaces = 5 - 1

for the first row, and:

spaces = 5 - 5

for the last row in figure 3.

That's how I do this by hand, and probably you do about the same. So have your program do it the same way. You have just three variables to consider:

1) spaces before the first *
2) the number of *'s to print on the line.
3) the largest number of *'s to print on any line

That's how you figure out the *'s to print for figure 3 and 4. Do that, and see what you can do with figure 5 and 6 (the Christmas tree shape figures).

Adak 419 Nearly a Posting Virtuoso

Your functions are not really functions, since you put a semi-colon on the end of their first line, in your program.

I've fixed that for you, and made some important notes in this code, for you. The function main() should not be called, inside your program, as noted. Also, all your fig() functions are now drawing the same tree shape.

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

//without the void's, your compiler may assume
//that an int is a parameter to the function
//Turbo C does that, among others.

void fig1(void);
void fig2(void);
void fig3(void);
void fig4(void);
void fig5(void);
void fig6(void);
//void exit(); exit is a C word, don't use 
//it for the name of a function.


int main()
{
 int cho, i;

 do {
   printf("[1] Figure 1\n");
   printf("[2] Figure 2\n");
   printf("[3] Figure 3\n");
   printf("[4] Figure 4\n");
   printf("[5] Figure 5\n");
   printf("[6] Figure 6\n");
   printf("[7] Exit\n\n");
   printf("Enter your choice:");
   scanf("%d",&cho);
   /* The next line isn't needed, here, if the user is careful
      Why do you want it? 
      Without it, if the user enters a letter, instead of a 
      number, the program enters an endless loop.
   */
   i = getchar(); //"pulls" the newline off the keyboard buffer
   if(cho==1)
   {
    fig1();
   }
   else if(cho==2)
   {
    fig2();
   }
   else if(cho==3)
   {
    fig3();
   }
   else if(cho==4)
   {
    fig4();
   }
   else if(cho==5)
   {
    fig5();
   }
   else if(cho==6)
   {
    fig6();
   }
  // else if(cho==7) { //handled by the do while loop

  }while(cho != 7);
  printf("\n\n\t\t\t    press enter when ready");
  i = getchar(); 
  ++i;
  return 0;
 }

void fig1(void)  //No semi-colon …
Adak 419 Nearly a Posting Virtuoso

TIME is not a variable, TIME is being replaced by the pre-processor, by the digit 5. So the compiler never see's TIME, and knows nothing about it.

You see the results of this 1) because the program is correct and 2) because the program will compile.

Adak 419 Nearly a Posting Virtuoso

If you have your pseudo code written out, then post it up. Of course, I know you didn't do it, and you're bull-shitting me, but that's OK. Everyone will try the "I'll lie and he'll buy it maybe, what have I got to lose?", tactic.

I've been around far too long to believe it, but I'm hoping you'll say "damn that Adak, I'll write down some pseudo code, and post it, just to prove he's wrong", and that will be fine. ;)

Veracity may be scarce here, but believe this - I will *not* post so much as one semi-colon of code, until I see you post up some pseudo code or actual code. Doesn't matter which one.

Put some "skin" into this effort. Don't post up "still having a problem", post up your attempt, and state clearly and specifically WHAT the problem(s) is/are.

I want to help you, and I want to believe you. You're just not making that possible, so far.

jonsca commented: Very direct +4
Adak 419 Nearly a Posting Virtuoso

Get to know the problem - really analyze it, in this case, by doing it by hand with paper and pencil.

After you get the steps down into small steps which you can readily identify, then write down those steps -- That's your pseudo code.

Check your pseudo code, that it's correct, and then put one small step onto one line, and see if you can make that logic, into actual C code.

Don't worry the details, for now. Get the "flow" of the program working. A function (or block of code), for input, for output, for processing, is common.

After you get the major logic code working, add in the details you put off, earlier.

And welcome to Top Down Design, and the forum. ;)

Post up your attempt at the above, and I'll show you a slick trick for programming the above. The reason is that programming is, after you get past the basics, a lot of problem solving. You have to get used to solving problems like this one, and the sooner you get into that, the better.

So, no code will I give you, right now. Work with it, and show what you come up with.

Adak 419 Nearly a Posting Virtuoso

This link has Turbo C/C++ 1.01, which I strongly recommend, because:

1) It's a newer product, and has fewer bugs than the older Turbo C 2.0
2) It has both a C++ and a C compiler - files with a dot c filename will be compiled with the C compiler, by default.

3) I still use it, frequently.

I recommend newer compilers and IDE's: free Visual Express or Code::Blocks + the Ming compiler, (as Dave Sinkula previously mentioned in this thread), but if you MUST use Turbo C, then Turbo C/C++ (which is commonly called Turbo C at times), is a good TC to use.

If you can't find what you're looking for there, Google "Borland Legacy Software", and follow the links.

Adak 419 Nearly a Posting Virtuoso

This is a bit of code showing how to move the cursor, using one API, in the console window.

//you need to include <windows.h>

void Gotoxy(int x, int y) {
   COORD coord;
   coord.X = x;
   coord.Y = y;
   SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

void function Where I want to move the console cursor(void)  {
  Gotoxy(1,5);
}
Adak 419 Nearly a Posting Virtuoso

If you use scanf(), you have to know what scanf() does and does not do:

1) For char input, scanf() will take *ONE and one ONLY* char. That means that the newline char from hitting the enter key, is still in the keyboard buffer.

Which means that the NEXT scanf() for a char will be taking the newline FIRST, and say "I've got my char, so I'm done here". Leaving you to believe it has magically "skipped" it's whole input.

2) For number input, scanf() will skip over whitespace char's - including newlines, so it's not a problem if there is a newline in the buffer, left over.

The solution is to put one of these, after EVERY scanf(), immediately:

getchar();

That will pull off the newline char, and stop the "skipping" behavior that you've seen.

Note carefully, Gerard's advice, above. Don't use &address, if address is a char array, and undoubtedly, fgets is a more polished way of getting user input. Scanf() can be used for most assignments, but you have to know how it works.

Adak 419 Nearly a Posting Virtuoso

The obvious trouble shooting step seems to be to try the sample code from MSDN, just as it is, and then substitute various values for the speed.

For each value, find out if it's working correctly. Record all the values that you test - good or bad. Then use the good values only, as possible speeds for your program to set.

That's the next step for the software portion, but I'm not satisfied with your lack of info from the CD manufacturer. CD drives haven't changed much over the years, so even though your CD drive is old, the manufacturer should be able to tell you what speeds are possible, and how to set them for that speed, in your program.

If you want the answers to this, you're going to have to be aggressive in seeking it out. This isn't the kind of info that a software forum is likely to be able to provide, unless they have someone familiar with low level drivers.

Adak 419 Nearly a Posting Virtuoso

What is the upper range of USHORT on your system? (check limits.h, etc.) Could you be overflowing the upper limit of it, or of the CD drive?

Adak 419 Nearly a Posting Virtuoso

The Cascade feature was the most noticeable feature of Minesweeper. You clicked on one square, and suddenly 5 or 10 or 20 squares were uncovered in front of your eyes, as if by magic.

Since it never uncovers a square with a mine, it added a lot of zip to the game - the game went by faster, especially when playing with a larger number of squares. The pseudo code in green, gave about the clearest description of the logic for the Cascade. I used it to describe the Cascade function, right in my program. Took me two tries to get the logic right, though.

If you have already turned in your program, I believe we can definitely mark this thread as "solved". ;)

I have not yet written the code to mark a mine. That's next.

Good luck with your studies!

Adak 419 Nearly a Posting Virtuoso

I couldn't find my old minesweeper game, so I started a new one. I found this description of the Cascade algorithm helpful, so I used it to help with that logic. I have only tested this function a few times, so I can't say it's OK, just yet.

/* 
"
Another interesting detail is the iterative nature of the cascade algorithm. 
It is clear that the queue data-structure can be replaced with any container 
data-structure. A stack is an obvious choice. Which begs the question: why 
the implementors did not use recursion to implement the algorithm? 
The use of recursion in this case would have considerably simplified the 
algorithm as it would obviate the need for the queue data-structure. The 
recursive algorithm would work as follows:

   1. If current square is a mine gameover, otherwise uncover square
   2. Count mines adjacent to current square
   3. If adjacent mine count is zero, uncover all adjacent covered squares 
      and make a recursive call for every one of them (steps 2-3)
"
*/
void cascade(int row, int col) {
  int i, mines, r=row, c=col;

  if(grid[row][col].n || grid[row][col].mines) 
    return;
  else {
    if(grid[r-1][c].n==9) grid[r][c].mines++;       //12 o'clock
    if(grid[r-1][c+1].n==9) grid[r][c].mines++;     //1:30 o'clock
    if(grid[r][c+1].n==9) grid[r][c].mines++;       //3 o'clock

    if(grid[r+1][c+1].n==9) grid[r][c].mines++;     //4:30 o'clock
    if(grid[r+1][c].n==9) grid[r][c].mines++;       //6 o'clock
    if(grid[r+1][c-1].n==9) grid[r][c].mines++;     //7:30 o'clock

    if(grid[r][c-1].n==9) grid[r][c].mines++;       //9 o'clock
    if(grid[r-1][c-1].n==9) grid[r][c].mines++;     //10:30 o'clock
    
  
    if(grid[r][c].mines==0) {
      grid[r][c].n=1;  //open this square
      //recursive call for all adjacent squares
      cascade(r-1, c);    //12 o'clock 
      cascade(r-1, c+1);  //1:30 o'clock 
      cascade(r, c+1);    //3 o'clock 
      cascade(r+1, c+1);  //4:30 o'clock 
      cascade(r+1, c); …
Adak 419 Nearly a Posting Virtuoso

I strongly suggest you take this subject up with forums or *newsgroups* that specializes in computer editing of images.

You've moved away from C programming, and you need to follow that. Come back if you have a C question or problem.

Adak 419 Nearly a Posting Virtuoso

The same way you know when a line ends - it finds the '\n' (newline) char. fgets() will have problems if the text is long, and has no newlines in it. That's odd, but I have seen text like that before.

Adak 419 Nearly a Posting Virtuoso

Check out "floodfill" and "Minesweeper" (the game),on Wikipedia. One of them should have an example of how it works.

A bomb detection game with no bombs being represented?? Say it ain't so! ;)

I will test it. I'm also looking around for my old minesweeper program, but it may have been lost some years in the past.

You always need to have the user be able to quit the game - MAYBE even save the current game; but definitely to quit it.

Adak 419 Nearly a Posting Virtuoso

I see these problems with your program:

1) non-bomb squares adjacent to your chosen square, don't "avalanche" open.

2) you can't mark a square as a bomb, like you can in Minesweeper

3) the game doesn't end when the last free square has been chosen. It should be congratulating me for winning the game.

4) there is no way to quit the game, either at the main menu, or while working with the playing grid.


To fix the ending, just count up the number of free squares remaining, and when the count reaches zero, the player is declared the winner and the program should return to the main menu. Also, set up a < Q to Quit> message and logic.

The "avalanche" function will be the most difficult fix, but give it a try. Come back if you get stuck.

Adak 419 Nearly a Posting Virtuoso

A great deal of what you want is included in Turbo C's help files.

After starting up the IDE (the editor inside Turbo C), click on "Help" on the far right hand side, and then on "Index".

One graphic function that you will certainly want to look at is "rectangle" (just start typing it and the help window will take you to it), and maybe "line", and possibly "setcolor", etc.

Along with a full explanation of these functions, it also has a complete sample program you can study and copy and paste, as well.

The above description is for Turbo C/C++ 1.01. Later versions may vary.

Regarding your previous problem - never have your program quit due to an error, without first printing out what the error was. Really elementary stuff like that, will save you a TON of time, in debugging.

Adak 419 Nearly a Posting Virtuoso

Use fgets in a while loop. When fgets() returns NULL, then you have reached the end of the text file. Aha!

Inside that while loop, fgets() will put each line into your char array, which must be large enough to fit all the names into for ONE line. (for even the longest row, plus 1 for the end of string char which it adds).

Then, you use strstr() to search for the target name, within your char array. If it returns a valid pointer (instead of NULL), then your name is in the char array.

The char array can be just one dimension, since each line from the file, will be handled sequentially.

If you want show - so do I. Put some skin into this assignment, and post your code to try this, and tell us what your problem is.

DON'T just say "Please fix this, it doesn't work". Because that doesn't work for us. We want to help, not be your homework bitch. ;)

Adak 419 Nearly a Posting Virtuoso

Until you start dreaming once in a while, about coding, you're not really coding! :)

Congrats on getting it to work - I'm sure it was a real learning experience. Working with strings in C is not that easy - kind of an "acquired taste", really.

Anyway, congrats again and well done. This kind of input, where the number of words varies from one line to the next, can be a real challenge for beginners.

Adak 419 Nearly a Posting Virtuoso

You have an array of structs with members. Why not just copy them char by char, into the appropriate member? You will use two pointers - one to tell you where the current char is in the buffer array, and one to tell you where that char goes, in the struct member.

I suggest using a while loop to do this, nested inside the while loop that fgets() the strings from the file. Might even use three of them:

j=0;
while((fgets()) {  //as I showed in my earlier post
  i=k=0;
  while(buffer[i] != '?') {
    struct[j].subject[k] = buffer[i];
  i=k=0;
  //repeat the above while for verb and object
  //resesting i and k to 0, but not j, for each of these
  //three inner while loops
  }
}

If you break this problem down into it's three parts, then the whole problem becomes very simple. That's the key solving this problem - and a great skill to develop, for a programmer.

Adak 419 Nearly a Posting Virtuoso

No, they're different languages, but Objective C can run C code, since it is a superset of C.

Read all about it, on Wikipedia: http://en.wikipedia.org/wiki/Objective-C

Adak 419 Nearly a Posting Virtuoso

If it's a binary number (don't let the hexadecimal value mislead you, i is still just a binary number, internally), and you moved the one's in that binary number, two columns to the left (filling up behind it with zero's).

What would you have?

We know that 0xff is 16 16's, or 16 * 16. So that's 1024, but now there's an adjustment needed, because the 4 part of 1024, has been over-written by zero's, from the << 2 bit shifting. So the 4 column of the binary number is now a zero.

Net effect is to remove the 4 from the answer, and 0xff << 2 becomes 1020 only.

A tutorial on it, should help. Google up one of the many tutorials on bit shifting, and go through it.

Adak 419 Nearly a Posting Virtuoso

You should have a doubt, because if your compiler will run the code, it will give you a NULL pointer assignment error, right at the end.

At least, that's what I got.

This kind of "fun and games with freakish C syntax ", is a total waste of time, and the sooner you move away from it, the better.

Even if you received no warnings or errors, what's the use of such syntax? It will never be portable, never be standard. Never be something you'd want to bet on would work without errors.

Useless, imo.

Adak 419 Nearly a Posting Virtuoso

I would change "relation" to "verb" and use fgets() to put each line of the file, into a char buffer[] array. Then take all the char's from the first up to the first question mark, and copy that into your subject member. Then take everything from that point, until the next question mark, as your verb member. The last bunch of char's (which would always end with the end of string char: '\0'), go into your object member.

Scanf() isn't a good function to use because each of these groups contain a variable number of spaces, which will be a witch for scanf() to work with.

Include string.h, and use that question mark - that's the key thing.

When you're done with one line, you're ready for the next line. You guessed it, this goes in an outer loop. fgets() returns NULL when it has reached the end of the file, so it works great right inside a while loop:

char buffer[85] = {'\0'};

while((fgets(buffer, sizeof(buffer), FilePointer)) != NULL) {

//rest of your code goes here for the handling of the file data

}
Adak 419 Nearly a Posting Virtuoso

A nice way to do this is to put each line of text, into a char buffer[] array, say about 10 char's larger than any line in the text. (roughly).

Then you can use the simpler index of the buffer[] array, to move around as you'd like, and string to float functions are a natural to use, as well.

atof() is one such function, and is defined in stdlib.h (so include that header file). strtof may also be available on your system.

With atof() it works like this:

double myfloat;
char buffer[90] = {"1234.5678"};

myfloat = atoi(buffer);

That's not a complete program, so it won't run. It's there to show the basic skeleton, of using atof(), only.

You can do the same thing by moving around a pointer, inside a file, but it is clumsy, more difficult, and more prone to errors that may destroy the file, or part of the data in the file.

This is the smart way, and the easy way, both.

Adak 419 Nearly a Posting Virtuoso

Here's the kind of info you really need:
http://www.st.com/stonline/books/pdf/docs/11950.pdf

Adak 419 Nearly a Posting Virtuoso

This is the C forum. If you want to get help with C++, you need to go to the C++ forum.

Casting the return from malloc, in C, will cause C compilers to NOT show the error you would otherwise get from using malloc, without including stdlib.h.

Otherwise, there is no harm in casting the return from malloc. Your code warnings here, have been restrained by that cast.

Adak 419 Nearly a Posting Virtuoso

Take each function, make a note of:

1) What the function does correctly

and

2) What the function does not do correctly

That's the first step to debugging your program, and that's what anyone who wants to help might need to do, right off.

This will help save them a lot of time, and give yourself a way to start trouble shooting this code, as well.

Saying "the program is incorrect" is really not that helpful - we would assume that was the case, or you wouldn't be here.

It's the specifics faults that are needed, for each function or block of code. When you get one function working right, put a big phat OK above the first line of that function.

Nobody knows your code, and your teacher, better than you do. You can do this. :)

Adak 419 Nearly a Posting Virtuoso

ADHR should be, by convention, a defined global variable or constant, (thus the all caps). First that value (defines in C are a straight substitution) is left shifted two places, then the result is cast as an integer.

Finally that value is returned from the function.

Adak 419 Nearly a Posting Virtuoso

Malloc() is part of stdlib.h, which you did not include. You would have received an error, except you cast the return from malloc(), so it didn't give you one.

In addition to the above advice, you need to include stdlib.h in your header list, and in C, there is little cause to cast the result from malloc().

Adak 419 Nearly a Posting Virtuoso

By PIC chip, I don't mean PIC cpu, I mean a Programmable Interrupt Controller chip. That's what takes the clock sweeps from a raw source, and divides them up. In a PC, it gives 1/3rd of the sweeps to the RAM, one third to the speaker, and one third to the clock() function of the cpu.

You may have it integrated into your 8051 chip, I'm not sure where that function is located, but that's what you need to find - something on the hardware level, that handles low level timing.

Have you Googled for that, or asked about this on the forums/newsgroups that are dedicated to this kind of interest? Any manufacturer or the 8051 should be able to give you the info you are looking for.

You are SO lucky to have the internet so widely available. Good luck! :D

Adak 419 Nearly a Posting Virtuoso

You need to look at your hardware for such small timing intervals, not software.

Are you using a 555 timer IC chip? What timer features does your PIC chip offer?

That's where you need to look - C that uses your hardware, rather than your OS.

Adak 419 Nearly a Posting Virtuoso

You can use strstr() to find a sub-string (word), within a string. In your case though, you just need to find line[0] == 'F', and that's your line. :)

I would go as far as testing it a bit further, though:

if((line[0]=='F') && (line[1]=='r') && (line[2]=='o') && line[3]=='m') {
    //rest of your code, in here.
}

Should be just what you need.

Adak 419 Nearly a Posting Virtuoso

Would you post up a small sample of the input file, which is giving you this problem. I'm having trouble visualizing what the problem could be.

Adak 419 Nearly a Posting Virtuoso

You still have two main resources, besides Google:

1) Manufacturer's. CD drives today work a LOT like the CD drives of yesterday, for compatibility reasons.


2) Software (especially free software or open source software), that controls CD drives. You might recall that Linux is entirely open source, AND that it controls CD drives -- hint hint hint. :p

Now get in there and dig around. These answers aren't going to just fall into your lap.

Adak 419 Nearly a Posting Virtuoso

You need to address these questions to the manufacturer's web site. Another idea would be to try asking on a forum for CD software, like ImgBurn.

You may need to ask several times before you get an answer, so don't be afraid to shop around. It's impossible to know how long something like this, might take.

As always, Google is your bud.

Adak 419 Nearly a Posting Virtuoso

@ Eivnay: Yes. That is a limitation of any Turing style computer.

On timing programs: The early PC's had the timer running off the PIC chip (programmable interrupt controller), using 1/3rd of it's clock sweeps.

That gives decent timing IF you have a DOS or real time operating system, not running anything else.

Windows naturally, is not so good at this. All calls for clock() are prioritized, and taken in turn with other requests.

Recently, Intel has come out with high precision timer hardware, which is in many new boards with Intel chipsets in them. Microsoft was supposed to be supplying the driver, and they wanted their own "multimedia timer" software to be used, instead. The "multimedia timer was a flop. Now MS is supposed to release patches that allow Windows to use the Intel high precision timer, but I have not seen how good it is, personally.

The advantages are two fold: 1) finer resolution given, and 2) very fast set up, allowing multiple times (think of several functions and the program as a whole), to be timed better.

Since the profiling programs rely on this so much, they will undoubtedly be on top of the latest and greatest timing available.

Giving actual machine cycles for a function sounds like Unix/Linux/BSD stuff. Have not seen that in any version of Windows, but I'm new with Windows 7.

Adak 419 Nearly a Posting Virtuoso

i simply want to print name of all files and folders of the drive using c language.

Programming forums in general, have a problem with that type of request. "I simply want some code for this problem", type of requests, don't go over well, I'm afraid.

Show some effort on your part, and post your code relating to this problem. In the sticky posts, the forum makes it clear what type of posts should be given help, and what type should not.

Adak 419 Nearly a Posting Virtuoso

Please post up a little snippet of code trying to do what you want, and let's see what the problem is.

Adak 419 Nearly a Posting Virtuoso

You don't want to over-write records and shuffle them around a lot - that's risky business, and unnecessary.

Instead, just mark the name or a record number (like an id number with students), as zero or '\0'.

Now, your program can tell that record has been deleted, and is available for editing with new record data, as you add your next record.

That saves a lot of dangerous data shuffling and overwriting, as well.

If you wind up with too many deleted records this way, your program will just write out all the non-deleted records, to a new record file, and you're good to go.

Adak 419 Nearly a Posting Virtuoso

Your problem is that your scale was constant. Stats charts have this problem, and when they do, they use a logarithmic scale to solve it.

No, I don't have code for it, but Google surely will have examples, this is very common.

Adak 419 Nearly a Posting Virtuoso

<Sorry, my ISP is acting up. Please delete this>

Adak 419 Nearly a Posting Virtuoso

Are you trying to dynamically size the array with malloc or calloc?

"something happened here" is a complete mystery to me.

Adak 419 Nearly a Posting Virtuoso

Second for Walt's recommendation - very clean and easy as well.

Adak 419 Nearly a Posting Virtuoso

It may not be guaranteed to be portable by the C standard, but I've never heard of a C compiler that doesn't have signed and unsigned char's.

I'm sure there's some minimalist one that is that way, but it's designed for embedded applications, I'd bet $$$.

Narue commented: void main is harmless 99.9% of the time, but we don't cut any slack for it. -4
Adak 419 Nearly a Posting Virtuoso

If you have Windows XP 32 bit, you will be able to run the Turbo C programs and IDE, on it. If you have the 64 bit version of Windows XP, then I don't believe you can run Turbo C, because it's 16 bit software.

You could perhaps use something like FreeDOS to give you the essential environment.

By all means, if it's possible, move up to Code::Blocks and a modern C compiler. I love Turbo C, but it has passed it's "use by" date.

Adak 419 Nearly a Posting Virtuoso

ok ! suppose i entered values for num : 2, 5 , 7, 9, 3
the program first check every value with the value inside the loop j ? which means it will check with the next value of num ?
for example,
here first value for num is 2 so the first value of num[j] would be 5 ?
am i right ?

Yes!

No sense comparing 2 with 2! ;)

Adak 419 Nearly a Posting Virtuoso

You could scanf() for a number, (getting the hours), a char (getting the colon), and another number, (getting the minutes), then one more number (getting the meter reading).

Hours and minutes with a two digit format might make your int's look different, but that can be handled in the printout.

I hesitate to recommend scanf(), but it can be used well, *if* the data is strictly formatted, and you know how scanf() works.

Adak 419 Nearly a Posting Virtuoso

The compiler will handle that, for any data type, automatically.

It's a bit awkward because you're working with mid and other variables, as pointers, instead of as an index.

Also, you repeat the calculation and assignment line of code for mid, twice. Move it to the top of the while loop, and you can just do it one time.

It appears to be good workable code. For a snippet, I would have hoped for a sort better than bubble sort, however. Even though it's an optimized bubble sort, it's still a big step down.

It's ironic that we get way faster computers, only to have the slowest sorter, re-emerge in popularity.