Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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);
printf("%c\n", character);
for (counter = 0; counter<length; counter++){
if (!(char_set[counter] == character)){
printf("%s\n", "checking char");
} else {
printf("character found in char_set" );
return counter;
}
}
printf("character not found in char_set");
return -1;
}
char *interpret_set(const char *input_set)
{
int loc = charpos('\\', input_set);
printf("%d", loc);
/*
int counter;
int length = strlen(input_set);
for(counter = 0; counter<length; counter++){
printf("%c", input_set[counter]);
if(input_set[counter] == '\\'){
printf("%s\n", " :true");
switch (input_set[counter++]) {
case 92:
output[counter] = '\\';
printf("Assigned a double escape.");
break;
case 110:
output[counter] = '\n';
printf("Assigned a new line.");
break;
case 114:
output[counter] = '\r';
printf("Assigned a carrage return.");
break;
case 116:
output[counter] = '\t';
printf("Assigned a tab.");
break;
default:
printf("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]);
}
return -1;
}
Input:
======
tes\t test
Results:
========
Executing the program....
$demo tes\t test
\
checking char
checking char
checking char
checking char
character not found in char_set-1t :false
e :false
s :false
t :false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.