Advertisement
dsmithhayes

matchString() Function

Nov 9th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. //This function matches two strings
  6. //as per defined by the user.
  7.  
  8. int matchString(char input[], char match[]){
  9.     //Check to see if the strings don't match up
  10.     if(!strcmp(input, match)){
  11.         //Return a bool of 0
  12.         return 0;
  13.     }else{
  14.         //Return a bool of 1
  15.         return 1;
  16.     }
  17. }
  18.  
  19. int main(int argc, char argv[]){
  20.     //Declare variables
  21.     char x[10];
  22.    
  23.     printf("Input: ");
  24.     gets(x);
  25.  
  26.     //Set a string to match.
  27.     char y[] = "Hello";
  28.  
  29.     //Check to see if matchString returns a 0 or 1.
  30.     if(!matchString(x, y)){
  31.         //0 Return
  32.         printf("\nWrong.\n");
  33.     }else{
  34.         //1 Return
  35.         printf("\nCorrect.\n");
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement