Quote Originally Posted by algorism View Post
You mean 10 to the 10 (not 100), i.e., what most humanoids call "ten billion". Since you are mallocing two arrays of this size, I assume your machine has at least 20 gigabytes of memory. Lucky you! You should still test the return value of malloc just in case. My pathetic machine refuses to allocate that much memory.

Most bipeds would also tell us what their program is supposed to do and give some sample input.

I don't know what you're talking about on "line 42".

Your indentation is weird. What does the end brace on line 52 match up with? (Actually, I see it now. Still.)

a and b shouldn't be global. Declare them in main instead.

Since there's no need for the cast, and sizeof(char) is 1 by definition, your malloc's can just be like:
Code:
    a.d = malloc(MAXDIGITS);
Use 'A' and 'Z' instead of 65 and 90. (Assuming that's what 65 and 90 mean.)

Don't flush stdin. It's not portable, technically undefined. (It causes my machine to turn on the coffee maker.) You can eat the newline like this:
Code:
    while (getchar() != '\n')
        ;
Or, more correctly (since getchar could return EOF):
Code:
    int c;
    while ((c = getchar()) != '\n' && c != EOF)
        ;
    // possibly handle an EOF ...
I know I am being unreasonable when the constraints are so huge but that's what's given as constraints. Here's a screenshot:
Most probably memory allocation issue-nz5gep6-png
Sorry, I forgot to add sample input and output.
Input:
4
65
566
11
1623455078

Output:
A
AB

ACDFGHIJKLNPQRSTUVW
---
I edited my code accordingly(removed fflush() and malloc problems) but it still doesn't help.
Code:
#include<stdio.h>#include<stdlib.h>
#define MAXDIGITS 10000000000
struct num
{
    int ndigits;
    char *d;
} a,b;
int main(void)
{
    a.ndigits=0;
    b.ndigits=0;
    a.d=malloc(MAXDIGITS);
    b.d=malloc(MAXDIGITS);
    int i,j,k,t,flag=0;
    scanf("%d",&t);
    //fflush(stdin);
    getchar();
    while (t!=0)
    {
        char p,q,r,x;
        int c;
        while((c = getchar()) != '\n' && c != EOF)
        {
            //scanf("%c",&x);
            if (c=='\n') break;
            //printf("%c",x);
            a.d[a.ndigits]=c;
            a.ndigits+=1;
        }
        //printf("\ndigits= %d",a.ndigits);
        //for(i=0;i<a.ndigits;i++)
        //printf("digit: \n%c",a.d[i]);
        for(i=0; i<a.ndigits; i++)
        {
            for(j=0; j<a.ndigits; j++)
            {
                printf("\ni= %d j= %d",i,j);
                if (i==j) continue;
                p=a.d[i];
                q=a.d[j];
                r=(p-'0')*10+(q-'0');
                printf("\np= %c q= %c r= %c",p,q,r);
                if (r>='A' && r<='Z')
                {
                    flag=1;
                    int rf=0;
                    for(k=0; k<b.ndigits; k++){printf("%d",k);
                        if (r==b.d[k])
                        {
                            rf=1;
                            break;
                        }
                        }
                    if (rf!=1)
                    {
                        b.d[b.ndigits]=r;
                        b.ndigits+=1;
                        rf=0;
                    }
                }
            }
        }
        for(i=0; i<b.ndigits-1; i++)
            for(j=0; j<b.ndigits-i-1; j++)
                if (b.d[j] > b.d[j+1])
                {
                    x=b.d[j];
                    b.d[j]=b.d[j+1];
                    b.d[j+1]=x;
                }
        if(flag==1)
            for(i=0; i<b.ndigits; i++)
                printf("%c",b.d[i]);
        else printf("\n");
        t--;
    }
    return 0;
}