Skip to content

Instantly share code, notes, and snippets.

@bullheadandplato
Created October 14, 2020 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bullheadandplato/75e52ee134b3890cf182e2ea14243e8e to your computer and use it in GitHub Desktop.
Save bullheadandplato/75e52ee134b3890cf182e2ea14243e8e to your computer and use it in GitHub Desktop.
Mac address cleaner
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
int main() {
char *garbage_mac = "CF97#6#B@3F%23AC$";
char *clean_mac = malloc(12);
int length = (int) strlen(garbage_mac);
int clean_mac_counter = 0;
for (int i = 0; i < length; i++) {
char current = garbage_mac[i];
if (current > 47 && current < 58) {
//current is number 48-57 is ascii range for 0...9
clean_mac[clean_mac_counter++] = current;
} else if (current > 64 && current < 91) {
//current is capital alphabet. A-Z ascii range 65-90
clean_mac[clean_mac_counter++] = current;
} else if (current > 96 && current < 123) {
//current is small alphabet. a-z ascii range 97-122
clean_mac[clean_mac_counter++] = current;
}else{
printf("Illegal character = %c\n",current);
}
}
printf("Cleaned mac address is = %s\n",clean_mac);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment