Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 04-11-2009
Member
 
Join Date: Nov 2009
Posts: 36
Percentage of loading

Hello everyone,

My program is done under Windows 7 and I do not change anything.

What I do is the percentage of loading of a piece of code. Let me explain. Basically I did an exercise with the selection sort and insertion sort after finishing the ordering of an array. I need to know, during the sort, how much percentage is done and maybe (if possible) to see even a bar loading! Everything from the terminal, ie without graphics or other stuff.

eg

[============] | / - | \ 50%

slashes, backslashes, etc. That would be affected during loading.
Reply With Quote
  #2  
Old 04-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: Percentage of loading

I do not think you can do in a standard manner, a system "that agrees with" would clear all the console (on Windows with system ("CLS") and then rewrite over the bar
Reply With Quote
  #3  
Old 04-11-2009
Member
 
Join Date: Nov 2008
Posts: 1,185
Re: Percentage of loading

You mean something like this?

Code:
#include <stdio.h>
#include <unistd.h>

int main(int argc, char** argv)
{
    for (int i = 0; i < 100; ++i)
    {
        printf("completed %d\r", i);
        fflush(stdout);
        sleep(1);
    }
    return 0;
}
Reply With Quote
  #4  
Old 04-11-2009
Member
 
Join Date: Nov 2009
Posts: 36
Re: Percentage of loading

hello, I hope so, that is what I mean ...

Could you explain it to me? I tried to compile it and tell me that goes for the loop

Code:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>

void isort(int a[], int n){
	int i;
	int x=0;
	int j=0;
	for(i=1; i<n; i++){
		x=a[i];
		j=i;
		while (j >0 && x< a[j-1]) {
			a[j] = a[j-1];
			j--;
		}
		a[j]= x;
	}
}

int main(int argc, char** argv)
{
	clock_t start, end, dif;
	float tempo=0;
	int N=0;
	int M=0;
	printf("Enter size of array: \n");
	scanf("%d",&N);
	printf("Now enter the range of elements: \n");
	scanf("%d",&M);
	
	int a[N]; 
	
	printf("\n\n\t\t***ISORT***\n\n");
	start=clock();
	isort(a,N);
	end=clock();
	dif=end-start;
	tempo=(float)dif/(float)CLOCKS_PER_SEC;
    for (int i = 0; i < 100; ++i)
    {
        printf("completed %d\r", i);
        fflush(stdout);
        sleep(1);
    }

    return 0;
}
I put the source to run the insertion sort ...

In practice as well to measure the time I load a bar with a percentage ...

eg [======== ========] 50%
Reply With Quote
  #5  
Old 04-11-2009
Member
 
Join Date: Nov 2008
Posts: 1,185
Re: Percentage of loading

The code is simple. printf uses \r fflush to go back and set output in case the terminal has its own internal buffer. Obviously not just copy and paste to do what you want. Must change the code because it sort of bothers to update the progress bar while you are ordering.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Percentage of loading"
Thread Thread Starter Forum Replies Last Post
C Program - Percentage using pointer syabab33 Software Development 1 08-05-2012 11:42 PM
What is the Program to calculate the percentage? Ekpah Software Development 3 08-12-2009 12:30 PM
Calculate grade based on percentage Adel123 Software Development 2 01-09-2009 04:51 PM
HTML/CSS Percentage problem Soft Pack Software Development 3 05-01-2009 11:00 PM


All times are GMT +5.5. The time now is 07:37 AM.