vendredi 26 juillet 2019

Prints last last capital instead of first one

It prints last capital letter in the input not first and whenever there is no capital letter in the input it prints random capital letter and no capital statement, I don't know why it doesn't end with return statement.

void fun(char x[],int y)
{
   if(x[y - 2] >= 'A' && x[y - 2] <= 'Z')
   {
      printf("First capital letter in the given input is:%c\n",x[y-2]);
      return;
   }else
      fun(x,y -1);
   }
   //this part works
   if(y == -1)
   {
      printf("No capital letter found\n");
      return;
   }
}

int main()
{

  char x[200];
  fgets(x,200,stdin);
  int count = 0;
  while(x[count] != '\0')
      count++;

  fun(x,count);

  return 0;
}

Aucun commentaire:

Enregistrer un commentaire