Whats wrong with my code in C?

I ran this code on my compiler,and it worked just fine.But the codechef online IDE isnt taking any of my scanf values ? Why is that?

#include<math.h>

int digits(long x);

int main(void) {
// your code goes here

int t;
printf("Enter the number of text cases :");
scanf("%d",&t);

long n[1100];
if(t>=1 && t<=1000)
{
for(int i=0;i<t;i++)
{
printf(“Enter the digit :”);
scanf(" %ld",&n[i]);

    }
}
int ctr;

long sum=0;
long temp;
for(int i=0;i<t;i++)
{
if(n[i] >=1 && n[i]<=1000000)

     {    temp=n[i];
             sum=0;
        ctr= digits(n[i]);
        for(int j=0;j<ctr;j++)
        {
            sum+=temp%10;
            temp=temp/10;
        }
        printf(" %ld\n",sum);
     }
 }
 
return 0;

}

int digits(long n)
{
int ctr=0;
while(n !=0)

  {   n=n/10;
    ctr++;
      
  }
  return(ctr);

}

Because you didn’t provide inputs to codechef IDE.

Please check the box “Custom Input” and then provide input then it will work like a charm ; P

1 Like

There really needs to be some kind of warning about this, as numerous people seem to have been stung by it in just the last few days (including Yours Truly ;)) Anyone coming from e.g. Hackerrank will doubtless be very confused by this :slight_smile:

Perhaps the first time you click Run, there should be a popup saying “Warning: You have not provided any custom input. Your program will not be able to read from stdin”, or somesuch?

Or perhaps after submission, there should be a message like “Warning: You provided no Custom Input, so stdin was empty”?

Edit:

Here’s another one XD

@vijju123 - would it be possible to get a feature like this implemented?

one thing…follow the input output format and don’t print unnecessary statements like Enter number of test cases and such

I think it was somewhere down the line. Will have to ask the devs. :slight_smile:

2 Likes