Created
October 2, 2013 04:25
-
-
Save clarknelson/6789140 to your computer and use it in GitHub Desktop.
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 <stdlib.h> | |
#include <string.h> | |
int charpos(const char character, const char *char_set) | |
{ | |
int counter; | |
int length = strlen(char_set); | |
for (counter = 0; counter<length; counter++){ | |
if (char_set[counter] == character){ | |
printf("%s\n", "character found in char_set" ); | |
return counter; | |
} | |
} | |
printf("%s\n", "character not found in char_set"); | |
return -1; | |
} | |
char *interpret_set(const char *input_set) | |
{ | |
int counter; | |
int length = strlen(input_set); | |
char output[100]; | |
for(counter = 0; counter<length; counter++){ | |
printf("%c\n", input_set[counter]); | |
if(input_set[counter] == '\134'){ | |
//printf("%s\n", "true"); | |
switch (input_set[counter+1]) { | |
case 92: | |
output[counter] = '\134'; | |
printf("%s\n", "Assigned a double escape."); | |
break; | |
case 110: | |
output[counter] = '\012'; | |
printf("%s\n", "Assigned a new line."); | |
break; | |
case 114: | |
output[counter] = '\015'; | |
printf("%s\n", "Assigned a carrage return."); | |
break; | |
case 116: | |
output[counter] = '\011'; | |
printf("%s\n", "Assigned a tab."); | |
break; | |
default: | |
printf("%s\n", "This escape sequence is not supported."); | |
break; | |
} | |
} else { | |
output[counter] = input_set[counter]; | |
//printf("%s\n", "false"); | |
} | |
} | |
return 0; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
if (argc > 3) { | |
printf("You entered too many arguements, please submit mytr in this format. \n Usage: mytr [-d] SET1 [SET2]"); | |
} else if(argc < 3) { | |
printf("You entered too few arguements, please submit mytr in this format. \n Usage: mytr [-d] SET1 [SET2]"); | |
} else { | |
interpret_set(argv[1]); | |
charpos('r', argv[1]); | |
} | |
return -1; | |
} | |
Results: | |
Executing the program.... | |
$demo test\thello\\rwill\\n test | |
t | |
false | |
e | |
false | |
s | |
false | |
t | |
false | |
t | |
false | |
h | |
false | |
e | |
false | |
l | |
false | |
l | |
false | |
o | |
false | |
\ | |
true | |
Assigned a carrage return. | |
r | |
false | |
w | |
false | |
i | |
false | |
l | |
false | |
l | |
false | |
\ | |
true | |
Assigned a new line. | |
n | |
false | |
character found in char_set |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment