fork download
  1. /* From: Douglas T. Martin, 05/25/2015 */
  2. /* Written for any generic C compiler. Can run inside a project in an */
  3. /* interactive development environment (IDE) or be compiled and made into an */
  4. /* executable file and run from a command line. */
  5. /* This file contains the following code: */
  6. /* translate(): Function to convert a string of English text to pig Latin */
  7. /* main(): The main program that requests the integer from the user */
  8. /* and reports the resulting summation. */
  9.  
  10. /* Problem #2 */
  11. /* Write a FUNCTION which takes in a String as a parameter and returns a Pig */
  12. /* Latin version of that string. */
  13. /* The program should be able to: */
  14. /* 1) handle punctuation */
  15. /* 2) Ignore numbers (i.e. if “500” is passed in, “500” is passed back) */
  16. /* 3) Handle multiple sentences */
  17. /* Pig Latin translation is simply taking the first letter of a “word” and */
  18. /* appending that letter to the end of the word with “ay” added to the end as */
  19. /* well. Example: “Alex, how did you do question 21?” should */
  20. /* translate to “lexAy, owhay idday ouyay oday uestionqay 21?” */
  21.  
  22.  
  23.  
  24. #include <stdio.h> /* library functions for file input/output */
  25. #include <stdlib.h> /* standard C library */
  26. #include <stdint.h> /* library of integer types */
  27. #include <string.h> /* library of string functions */
  28.  
  29. /* Declare functions below */
  30.  
  31.  
  32. /* Declare global variables below */
  33. static char inputBuffer[] = "Translate this English text to Pig Latin. 10 words total.\n"; /* 57 characters + \n */
  34. static char outputBuffer[100]; /* Allocate enough space to add 'ay' to most words */
  35.  
  36.  
  37. void translate (void)
  38. {
  39. int j; /* counter for input buffer position beginning of word */
  40. int k; /* counter for input buffer position end of word */
  41. int m; /* counter for output buffer position */
  42.  
  43. j = 0;
  44. k = 0;
  45. m = 0;
  46. while (j < 57)
  47. {
  48. outputBuffer[j] = inputBuffer[j+1];
  49. j++;
  50.  
  51. } // end of while loop
  52.  
  53. printf ("\nInput buffer contents: %s", inputBuffer);
  54. printf ("\nOutput buffer contents: %s", outputBuffer);
  55. return;
  56. }
  57.  
  58.  
  59.  
  60. int main(void) /* Start of main loop */
  61. {
  62.  
  63. int i; /* Counter variable */
  64. for (i = 0; i < 100; i++)
  65. {
  66. outputBuffer[i] = " "; /* Initialize the output buffer */
  67. }
  68. printf(""\nTesting the printf statement.");
  69.  
  70. translate();
  71. return 0; /* return 0 to terminate main loop */
  72. } /* end of main() loop */
  73.  
  74. /* This is what the output looks like when it runs: */
  75. /* */
  76. /* */
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘translate’:
prog.c:41:7: warning: variable ‘m’ set but not used [-Wunused-but-set-variable]
   int m; /* counter for output buffer position */
       ^
prog.c:40:7: warning: variable ‘k’ set but not used [-Wunused-but-set-variable]
   int k; /* counter for input buffer position end of word */
       ^
prog.c: In function ‘main’:
prog.c:66:21: warning: assignment to ‘char’ from ‘char *’ makes integer from pointer without a cast [-Wint-conversion]
     outputBuffer[i] = " "; /* Initialize the output buffer */
                     ^
prog.c:68:12: error: stray ‘\’ in program
   printf(""\nTesting the printf statement.");
            ^
prog.c:68:12: error: expected ‘)’ before ‘nTesting’
   printf(""\nTesting the printf statement.");
            ^~~~~~~~~
            )
prog.c:68:43: warning: missing terminating " character
   printf(""\nTesting the printf statement.");
                                           ^
prog.c:68:43: error: missing terminating " character
   printf(""\nTesting the printf statement.");
                                           ^~~
prog.c:68:10: warning: zero-length gnu_printf format string [-Wformat-zero-length]
   printf(""\nTesting the printf statement.");
          ^~
prog.c:71:12: error: expected ‘;’ before ‘}’ token
   return 0;                                 /* return 0 to terminate main loop */
            ^
            ;
 } /* end of main() loop */
 ~           
stdout
Standard output is empty