Skip to main content

Posts

Showing posts with the label searching

Day 11: Statistics, Sorting, and Searching

Sorting Selection sort Homework Cipher Code in action Code for Cipher.h #ifndef _CIPHERH_ #define _CIPHERH_ #include <stdio.h> #include <string.h> #include <stdlib.h> char *getInput(void) {   int mem=16;    char *message=malloc(mem); //Preallocate memory   printf("Input Message\n"); fgets(message,mem,stdin); //Take user input  while(message[strlen(message)-1]!='\n') //Check if there's still space { mem*=2;  message=realloc(message,mem); //Double amount of space fgets(message + mem/2 - 1, mem/2 + 1, stdin); //Read the rest of the line } return message; //return character array message } int EncryptMessage(void) {   char *message=getInput(); //call getInput function   int ch; //initialize variable ch      int shift; //initialize variable shift      printf("\nInput number of characters to shift: \n");   scanf("%i",&shift); //ask user t...