/* Source code for Warner Soft */ #include // Required for I/O functions and FILE pointer #include // Required for strcmp /* Usage: AddKeyword("String\n", "filename", "mode"); */ /* Return: 0 if Error, 1 if Succeeded */ int AddKeyword(char *str, char *filename, char *filemode) { FILE *filein; /* do not change this field, creates a file pointer */ if ((filein=fopen(filename, filemode)) == NULL) { // Opens File return 0; // Return 0 if error occured } fputs(str, filein); /* Writes string to the filename */ fclose(filein); /* Do not change this field, closes file stream */ return 1; // Return 1 if succeeded } /* Usage: GetKeyword("String\n", "filename", "mode"); */ /* Return: 0 if Error, 2 if no match, 1 if Match */ int GetKeyword(char *str, char* filename, char *filemode) { FILE *filein; /* Declare a File pointer [do not change this field] */ if ((filein=fopen(filename, filemode)) == NULL) { /* Open File */ return 0; /* Return 0 if error occured */ } char szBuffer[32] = "NULL"; /* Buffer to hold 32 characters of data */ char strBuffer[32] = "NULL"; /* Buffer to hold 32 characters of data */ while (!feof(filein)) { /* While file is not at the END */ fgets(strBuffer, sizeof(strBuffer), filein); /* Read data from file into the buffer */ printf(strBuffer); /* NOTE: This line is here only, to display all the items listed in the file, (for testing purposes) */ if (strcmp(str,strBuffer) == 0) { /* Compare the string in the file with your string if its true it strcmp will return 0 (meaning true) */ fclose(filein); /* Do not change this field Closes the file if Match is found */ printf("TRUE\n"); /* NOTE: This line is here only, to display if a match has been found, you may remove it. (for testing purposes) */ return 1; } // Closing the if statement } // Closing the while loop fclose(filein); /* Do not change this field, closes the file */ return 2; // Return 0 = no match found }