I'll probably get flack for doing your homework, but I want to see if I can still remember C.
[CODE=C]
/*
* Programmer: slapshot_oi
* Date: October 30, 2008
*/
#include <stdio.h>
#define FALSE 0
#define TRUE 1
int isHydroxide(char* str, int size);
int isHydroxide(char* str, int size){
/*Checks if the second-to-last char is
'o' or 'O', and if the last char is 'h' or 'H'*/
if(str[size] == 0x4F || str[size] == 0x6F)
if(str[size + 1] == 0x48 || str[size + 1] == 0x68)
return TRUE;
return FALSE;
}
int main (int argc, char **argv){
char* input = NULL;
int i = 0;
printf("\n\n Enter a chemical compound: ");
scanf("%s", input)
/*Finds the length of the array minus 1*/
while(input[i] != '\0')
i ++;
if(isHydroxide(input, i))
printf("\n\n The compound %s is a hydroxide", input);
else
printf("\n\n The compound %s is not a hydroxide", input);
return 0;
}
[/CODE]
You'd better compile this to check this man, 'cause I didn't. I wrote this all from memory based on what I learned over two years ago.
By the way, if you can't figure out a simple program like this without asking for help right off the bat, you're in for a tough semester.
|