SHARE
TWEET

Untitled

a guest Nov 19th, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>  
  2. #include <stdlib.h>
  3. #include <iostream>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <assert.h>
  7.  
  8.  
  9. const int MAX_NAME_LEN = 50;
  10. struct student
  11. {
  12.     char name[MAX_NAME_LEN];
  13.     unsigned int id;
  14.     unsigned int age;
  15. };
  16.  
  17. char Vowels[] = { 'A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u' };
  18.  
  19. char* wheelOfFortune(char* a_answer);
  20. char* wheelOfFortune2(char* a_answer);
  21. char checkVowel(char a_letter);
  22. void ninjaEdit1(student s);
  23. void ninjaEdit2(student* p_s);
  24.  
  25. int main()
  26. {
  27.     //Question 1: Wheel of Fortune
  28.     char a_answer[] = "Hello World";
  29.     int length = strlen(a_answer);
  30.     char* clue1 = (char*)malloc(length + 1);
  31.     char* clue2 = (char*)malloc(length+1);
  32.    
  33.     clue1 = wheelOfFortune(a_answer);
  34.     clue2 = wheelOfFortune2(a_answer);
  35.     assert(strcmp(clue1, clue2) == 0);
  36.  
  37.     printf("%s\n\n%s", clue1, clue2);
  38.  
  39.     //Question 2: Ninja Edits
  40.     student s;
  41.     printf("Enter Your Name: ");
  42.     scanf_s("%s", s.name);
  43.     printf("Enter Your Age: ");
  44.     scanf_s("%i", s.age);
  45.     printf("Enter Your ID: ");
  46.     scanf_s("%i", s.id);
  47.     ninjaEdit1(s);
  48.  
  49.     student* p_s;
  50.     p_s = &s;
  51.     ninjaEdit2(p_s);
  52.  
  53.     free(clue1);
  54.     free(clue2);
  55. }
  56.  
  57. char checkVowel(char a_letter)
  58. {
  59.     bool flag = false;
  60.     for (int j = 0; j < 10; j++)
  61.     {
  62.         if (a_letter == Vowels[j])
  63.         {
  64.             a_letter = Vowels[j];
  65.             flag = true;
  66.             break;
  67.         }
  68.     }
  69.     if (!flag)
  70.     {
  71.         if (isblank(a_letter))
  72.         {
  73.             a_letter = ' ';
  74.         }
  75.         else
  76.         {
  77.             a_letter = '_';
  78.         }
  79.     }
  80.     return a_letter;
  81. }
  82.  
  83. char* wheelOfFortune(char* a_answer)
  84. {
  85.     int length = strlen(a_answer);
  86.     char* a_clue = (char*)malloc(length+1);
  87.     for (int i = 0; i < length; i++)
  88.     {
  89.         a_clue[i] = checkVowel(a_answer[i]);
  90.     }  
  91.     a_clue[length] = '\0';
  92.  
  93.     return a_clue;
  94.     free(a_clue);
  95. }
  96.  
  97. char* wheelOfFortune2(char* a_answer)
  98. {
  99.     int length = strlen(a_answer);
  100.     char* a_clue = (char*)malloc(length + 1);
  101.     for (int i = 0; i < length; i++)
  102.     {
  103.         *(a_clue+i) = checkVowel(a_answer[i]);
  104.     }
  105.     a_clue[length] = '\0';
  106.  
  107.     return a_clue;
  108.     free(a_clue);
  109. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top