fork(2) download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. #define MAX_LEN 10
  6.  
  7. int hydroxide(char *compound);
  8.  
  9. int
  10. main(void)
  11. {
  12. char compound[MAX_LEN];
  13. int i, num;
  14.  
  15. printf("Enter compound> \n");
  16. scanf("%s", compound);
  17.  
  18. for (i = 0; i < strlen(compound); ++i) {
  19. if (islower(compound[i]))
  20. compound[i] = toupper(compound[i]);
  21. }
  22.  
  23. num = hydroxide(compound);
  24.  
  25. printf("%d", num);
  26.  
  27. return(0);
  28. }
  29.  
  30. int hydroxide(char *compound)
  31. {
  32. char end[4], *temp;
  33. int last, status;
  34.  
  35. last = strlen(compound);
  36.  
  37. strcpy(end, &compound[last - 2]);
  38.  
  39. /* Commented
  40.  * if (end[0],end[1]) > 0) {
  41.  * temp = end[last - 2];
  42.  * end[last - 2] = end[last - 1];
  43.  * end[last - 1] = temp;
  44.  * }
  45.  */
  46. /* Condition updated */
  47. if ( (end[0] == 'H' && end[1] == 'O') || (end[0] == 'O' && end[1] == 'H') ) {
  48. status = 1;
  49. }
  50.  
  51. return(status);
  52. }
  53.  
Success #stdin #stdout 0s 2296KB
stdin
CH3OH
stdout
Enter compound> 
1