Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // usage: rot.exe <#> <left/right> "<string>"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc, char *argv[]){
- char* input = argv[3]; // get input
- char* shift = argv[2]; // location of shift
- char* num = argv[1]; // #num input
- int shiftAmount = atoi(num);
- if(num == NULL || input == NULL || shift == NULL){
- printf("Invalid Usage!\n");
- exit(8);
- }
- int i; // iterator
- if((strcmp(shift, "left") == 0) || (strcmp(shift, "right") == 0)){
- if(strcmp(shift, "right") == 0){
- for(i = 0; i < strlen(input); i++){
- if(input[i] + shiftAmount <= 126)
- input[i] = input[i] + shiftAmount;
- else
- input[i] = input[i] + shiftAmount - 94;
- }
- }else{
- for(i = 0; i < strlen(input); i++){
- if(input[i] - shiftAmount >= 32)
- input[i] = input[i] - shiftAmount;
- else
- input[i] = input[i] - shiftAmount + 94;
- }
- }
- }else{
- printf("Invalid Direction of Shift!\n");
- exit(8);
- }
- puts(input);
- // free up mem
- free(&input);
- free(&shift);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement