fork(4) download
  1. /*
  2.  * File: isPasswordValid.c
  3.  * Author: srkrishnan
  4.  *
  5.  * Created on June 29, 2011, 11:41 PM
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. /*
  12.  *
  13.  */
  14.  
  15. int isPassowrdValid(char *pass)
  16. {
  17. int alpha=0,num=0,p=0,valid=0;
  18. char *str=pass;
  19. while(*str)
  20. {
  21. if(*str>='a' && *str<='z')
  22. alpha++;
  23. if(*str>='0' && *str<='9')
  24. num++;
  25. p++;
  26. str++;
  27. }
  28. if(alpha!=0 && num!=0 && alpha+num==p && p>=5 && p<=12)
  29. valid=1;
  30. else
  31. valid=0;
  32.  
  33. str=pass;
  34. char *t=NULL,*b=NULL,*c=NULL;
  35. while(*str)
  36. {
  37. t=str+1;
  38. while(*t)
  39. {
  40. if(*t==*str)
  41. {
  42. b=t;
  43. c=str;
  44. while(*t && *c)
  45. {
  46. if(c==b)
  47. break;
  48. if(*c!=*t)
  49. break;
  50. c++;
  51. t++;
  52. }
  53. if(c==b)
  54. {
  55. valid=0;
  56. break;
  57. }
  58. }
  59. t++;
  60. }
  61. str++;
  62. }
  63. return valid;
  64. }
  65.  
  66. int main(int argc, char** argv) {
  67.  
  68. printf("%d",isPassowrdValid("cb124"));
  69. return (EXIT_SUCCESS);
  70. }
  71.  
Success #stdin #stdout 0s 1720KB
stdin
Standard input is empty
stdout
1