pls help to fix the code! 
Author Message
 pls help to fix the code!

You have managed to omit:

1. What you want your program to do.
2. What your program does instead.
3. The actual behaviors of your program, while it is not doing what you
want.
4. A main() entry point for your program.

Apart from this, there are any number of classic beginner errors such as the
use of scanf().

Why not post a tiny bit of your code, that has a describable problem, and
describe the problem? That way, one of us can offer assistance.
--

Paul Lutus
www.arachnoid.com


<snip>



Mon, 19 Nov 2001 03:00:00 GMT  
 pls help to fix the code!
Hi,
  I would like to perform the algorithm:
Given abbab
abb a
bba b
bab a
bab b
the sort the first 3 characters become
abb a
bab a
bab b
bba b
and write the final stream aabb out to file.
I perform the following code.
But it gives wrong result.
Anyone can help me to fix it? and
and fast method? as I feel it is very
slow when a large file comes in even quick sort.
Thanks in advance

DO()
{
    FILE *filein,*fileout;
    char in[15],*p,x,out[15],tmp[MAX],Input[MAX];
    char * Array;
    char ** Source,*temp;
    long int Len, i,n=0;
    char Elem[10];

    printf("Enter an input file\n");
    scanf("%s",in);
    printf("Enter an output file\n");
    scanf("%s",out);
    printf("Enter the N number \n");
    scanf("%d", &N);

    N=N+1; /* N =3 in my case */

    filein=fopen(in,"rb");
    fileout=fopen(out,"wb");

    setmode(fileno(filein),O_BINARY);
    setmode(fileno(fileout),O_BINARY);

        for(;;){

    Len = fread((char *)Input,1,(size_t)MAX,filein);

    if(Len==0) break;
    pArray = malloc(nLen*2);
    memcpy(Array,Input,Len);
    memcpy(Array+Len,Input,Len);
    Source = malloc(Len*sizeof(char*));
        for(i=0; i<Len; i++)
        {
                Source[i] = &Array[i];
        memset(Elem,0,sizeof(Elem));
        memcpy(Elem, Source[i], N);
        }

    qsort( Source, Len, sizeof(char *), compare);
    for(i=0; i<Len; i++)
    {
        memset(Elem,0,sizeof(Elem));
        memcpy(Elem, Source[i], N);
    }
        for(i=0; i<Len; i++)
        {
      fputc(*(Source[i]),fileout);
        }
        } //end for
        free(Array);
        free(Source);

printf("Press any key ...\n");
        getch();
    fclose(filein);
        fclose(fileout);

Quote:
}

int compare(const void *elem1, const void *elem2 )
{
    char *pElem1, *pElem2;
        pElem1 = *((char**)elem1)+1;
        pElem2 = *((char**)elem2)+1;
    count++;
    return memcmp( pElem1, pElem2, N - 1 );
Quote:
}



Tue, 20 Nov 2001 03:00:00 GMT  
 pls help to fix the code!

alex a crit:

Quote:
> Hi,
>   I would like to perform the algorithm:
> Given abbab
> abb a
> bba b
> bab a
> bab b
> the sort the first 3 characters become
> abb a
> bab a
> bab b
> bba b
> and write the final stream aabb out to file.
> I perform the following code.
> But it gives wrong result.
> Anyone can help me to fix it? and
> and fast method? as I feel it is very
> slow when a large file comes in even quick sort.
> Thanks in advance

Your explaination was not very cleared... In fact, i don't know what u
are trying to do

Quote:

> DO()

What is this? did u mean...

do
{
    <your code>

- Show quoted text -

Quote:
} while (<condition>)
> {
>     FILE *filein,*fileout;
>     char in[15],*p,x,out[15],tmp[MAX],Input[MAX];
>     char * Array;
>     char ** Source,*temp;
>     long int Len, i,n=0;
>     char Elem[10];

>     printf("Enter an input file\n");
>     scanf("%s",in);
>     printf("Enter an output file\n");
>     scanf("%s",out);
>     printf("Enter the N number \n");
>     scanf("%d", &N);

>     N=N+1; /* N =3 in my case */

>     filein=fopen(in,"rb");
>     fileout=fopen(out,"wb");

>     setmode(fileno(filein),O_BINARY);
>     setmode(fileno(fileout),O_BINARY);

>         for(;;){

>     Len = fread((char *)Input,1,(size_t)MAX,filein);

>     if(Len==0) break;
>     pArray = malloc(nLen*2);
>     memcpy(Array,Input,Len);
>     memcpy(Array+Len,Input,Len);
>     Source = malloc(Len*sizeof(char*));
>         for(i=0; i<Len; i++)
>         {
>                 Source[i] = &Array[i];
>         memset(Elem,0,sizeof(Elem));
>         memcpy(Elem, Source[i], N);
>         }

>     qsort( Source, Len, sizeof(char *), compare);
>     for(i=0; i<Len; i++)
>     {
>         memset(Elem,0,sizeof(Elem));
>         memcpy(Elem, Source[i], N);
>     }
>         for(i=0; i<Len; i++)
>         {
>       fputc(*(Source[i]),fileout);
>         }
>         } //end for
>         free(Array);
>         free(Source);

> printf("Press any key ...\n");
>         getch();
>     fclose(filein);
>         fclose(fileout);
> }

> int compare(const void *elem1, const void *elem2 )
> {
>     char *pElem1, *pElem2;
>         pElem1 = *((char**)elem1)+1;
>         pElem2 = *((char**)elem2)+1;
>     count++;
>     return memcmp( pElem1, pElem2, N - 1 );
> }

--
Anyone uses that signature feature in their mail program?


Wed, 21 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Pls help me to fix the code!

2. Help on my C code, dont understand how to fix my compiler errors (PLEASE HELP)

3. expert advice needed pls, pls, pls

4. Receive error on compiling single link list codes--pls help

5. TreeView Tooltip code: pls help with the error

6. Help with fix to tab delimted conversion code

7. Can someone help me fix this code?

8. Please help fix code.

9. please help me fix my code

10. Pls, how to change code in VC?

11. Fixed-size arrays as event args in managed code

12. How can I fix these Error Messages (code below)

 

 
Powered by phpBB® Forum Software