Skip to content
Permalink
040c0c153e
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
68 lines (45 sloc) 1.02 KB
#include <stdio.h>
#include <string.h>
#define BUFFSIZE 30
int process_first(char *buffer){
int strlen = 0;
//Work out length of string
for (strlen = 0; strlen <= BUFFSIZE; strlen++){
if (buffer[strlen] == '\0'){
return strlen;
}
}
return strlen;
}
int checkPassword(char *buffer, int strlen){
char magicWord[] = "HelloWorld";
char tempbuffer[strlen];
int y = 0;
for (int x = strlen - 1; x >= 0; x--){
tempbuffer[y] = magicWord[x];
y+=1;
}
tempbuffer[strlen] = '\0';
if (strcmp(tempbuffer, buffer) == 0){
return 0;
}
else{
return -1;
}
}
void main(void){
char buffer[BUFFSIZE];
printf("Enter Password> ");
fgets(buffer, BUFFSIZE, stdin);
//Remove the Newlines
buffer[strcspn(buffer, "\r\n")] = 0;
//Get the Length
int strlen = process_first(buffer);
int returnVal = checkPassword(buffer, strlen);
//int returnVal = process_first(buffer);
if (returnVal == 0){
printf("Win!!\n");
}
else
printf("Lose\n");
}