xitrum69 31 Newbie Poster

hix you got some mistakes in C pointer programming.
1/ You declared a pointer variable and allocated it by using *memsectptr ????

int *memsectptr;
 *memsectptr = malloc(sectorsize); 
....
ES:_BX = *memsectptr;

the code should be

int *memsectptr;
memsectptr = malloc(sectorsize);
....
ES:_BX = memsectptr;

and the following code will print data in a sector

for(i=0; i<(sectorsize * noofsectors); i++)
{
    printf("%X", *(memsectptr+i));
}

xitrum

xitrum69 31 Newbie Poster

I think you have to define two arrays and two mutex as global variables such as:
two arrays: 1st_array, 2nd_array
two mutex: 1st_mutex, 2nd_mutex

and we will have three functions as below

void ReaderThread(....) // 1st thread
{
    ....
    lock 1st_mutex;
    if (1st_array is empty) 
    {
          read info from stdin -> put to 1st_arrray
    }
    unlock 1st_mutex;
    delay
    continue;
    ....
}

void TranslateThread(....) // 2nd thread
{
    ....
    lock 1st_mutex;
    try lock 2nd_mutex;
    if (2nd_array is not busy) 
    {
            if (1st_array is not rempty)
            {
                   translate it and pass the result to 2nd_array;
                   empty 1st_array;
            }
            unlock 2nd_mutex;
    }
    unlock 1st_mutex;
    delay
    continue;
    ....
}

void ProcessThread(....) // 3rd thread
{
    ....
    lock 2st_mutex;
    if (this is new result) 
    {
            process 2nd_array;
            empty 2nd_array;
    }
    unlock 2st_mutex;
    delay
    continue;
    ....
}

That's it.
xitrum

xitrum69 31 Newbie Poster

Hi All,
I am getting confused as to how to get this data into there in the start (wether to use a struct or what) and also how to output the data and in what form (%c, %d, etc.).
If you could offer any advice it would be greatly appreciated.
Dinklebaga

For reading a sector, simply you should define a buffer such as

char buff[512];

then use "%X" to print the hex format.

xitrum69 31 Newbie Poster

please write a programme to sort array of integers using quick sort

Read Quick sort algorithm at
http://cprogramminglanguage.net/quicksort-algorithm-c-source-code.aspx

And try to write a simple function yourself.

Good luck,
xitrum

xitrum69 31 Newbie Poster

your request are so general. Please specify yr requirement to get a detail help.

xitrum69 31 Newbie Poster

Please take your time to study curl library (source code) where you can find a simple example to understand how to post a http request with C programming.

xitrum69 31 Newbie Poster

post your code. I will take my time to review your code soon

xitrum69 31 Newbie Poster

I think the libcurl can help you
http://curl.haxx.se/libcurl/ if you want to talk to a website.

If you want to launch a web brower, you can use system() function to call IExplore.exe program.

xitrum69 31 Newbie Poster

in the main function, you have to replace the displayArray (numbers) with the display (numbers) function.

Have fun.

xitrum69 31 Newbie Poster

well I forgot to edit the last part. now with close } there is no error but there is still problem with agorithm to sort. Anyone can produce my code with the correct algorithm please? I have finish a lot of my time but still have not finish it.

Just copy and paste. I tested. It ran good.

void sort(int num[],int i)
{
	int k,k2,temp;
	for (k=0; k<N-1; k++)
		for (k2=k+1; k2<N; k2++)
			if (num[k] > num[k2])
			{
				temp = num[k];
				num[k] = num[k2];
				num[k2] = temp;
			}
	return ;
}
iamthwee commented: For getting it wrong. -3
xitrum69 31 Newbie Poster

Nope, that's your function, not his. What's the purpose of that int i parameter if it is not used?. And C doesn't allow the declaration of an type inside of a for loop.

Exactly, the "i" paramter is not used in this case.
My puprose is to fix the errors from Wuss to change his sort algorithm and try to unchange the sort prototype.

Due to I am using the gcc to test the code, thanks for your reminder. The following is my modification code:

void sort(int num[],int i)
{
	int k,k2,temp;
	for (k=0; k<N-1; k++)
		for (k2=k; k2<N; k2++)
			if (num[k] > num[k2])
			{
				temp = num[k];
				num[k] = num[k2];
				num[k2] = temp;
			}
	return ;
}
xitrum69 31 Newbie Poster

Yes, you missed the closing bracket of the function sort and wrong in sort algorithm. Here is your function

void sort(int num[],int i)
{
       int k,k2,temp;
       for (int k=0; k<N-1; k++)
           for (int k2=k; k2<N; k2++)
               if (num[k] > num[k2])
              {
                   temp = num[k];
                   num[k] = num[k2];
                   num[k2] = temp;
               }
      return ;
}
xitrum69 31 Newbie Poster

Here is your code

int main ()
float M[3][3]=
{
   {0.01, 1.02, 2.05},
   {2.01, 0.00, 5.00},
   {3.01, 4.00, 0.40}
};

float mn, mx;
for (int i = 0; i < 3; i++)  // change the column for testing only HERE
// for (i=0; i<1; i++) to get max = 3.01 and min = 0.01
// for (i=2; i<3; i++) to get max = 5.00 and min = 0.40
{    
   mn = mx = M[i][0]; 
   for (int j = 1; j < 3; j++)     // DO NOT change the column here
   {        
      if (M[i][j] < mn)            
         mn = M[i][j];        
      if (M[i][j] > mx)            
         mx = M[i][j];    
   }    
}
printf("min=%.2f + max=%.2f\n",mn,mx);
system ("pause");	    
return 0;
}
xitrum69 31 Newbie Poster

I suppose that you are using C language. Here is your function

#include <stdlib.h>

int  RunSystemCmd(char *pfilename)
{
    char buff[512] = {0};
    if (pfilename == NULL) return -1;
    sprintf(buff,"HandBrakeCLI -i /dev/hdc -o /root/%s -b 1024 -B 128 -R 48 -E faac -f mp4 -w 368 -l 208 -m", pfilename);
    return system(buff);
}
xitrum69 31 Newbie Poster

I think you should change your code as following:

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

using namespace std;
main()
{ 
  // char *filenames[] = {"file1","file2","file3",NULL};
  int n; 
  char buf[256];
  FILE *fp = NULL;
  cout<<" enter number of input files :";
  cin>>n;
  for(int i =0;i < n;i++){
    sprintf(buf,"file%d.dat",i+1);
    fp = fopen ( buf,"w");
    if (fp == NULL) break;
    fprintf(fp,"Copy \"C:\\Program Files\\prog\\prog%d.IN\" prog.In\n",i+1);
    fclose(fp);
   }
}
Ancient Dragon commented: Thanks for taking the time to use code tags :) +34