Permalink
Cannot retrieve contributors at this time
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?
6052-Labs/Week3_Compiler/sources/4_Process.c
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
68 lines (45 sloc)
1.02 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); | |
} |