Guest User

Untitled

a guest
Dec 15th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <ctype.h>
  5.  
  6. static int counter = 0;
  7. static int wordlength = 0;
  8. static int lwlm = 0;        //last word length marker (just too long to ues everywhere)
  9. static int inputlength = 0;
  10.  
  11. void
  12. useprinter (int** input, int* word, int wordsizes[],int words)
  13. {
  14. printf("printing seems to be turning on");
  15.   for (int i = 0; i < words; i++)
  16.     {
  17.  
  18.       for (int j = 0; j < wordsizes[i]; j++)
  19.     {
  20.  
  21. //  ISSUE PLACE   printf ("%c", (*input+i)[j]);
  22. //  ISSUE PLACE   (*input+i)[j] = 0;
  23. //printf("q");   FOR TESTING
  24.     }
  25.       printf(" ");
  26.   //    wordsizes[i] = 0;
  27.     //  word[i] = 0;
  28.     }
  29.   printf ("\n");
  30.  
  31.  
  32. }
  33.  
  34.  
  35.  
  36. int
  37. main (void)
  38. {
  39. int** input = malloc(sizeof(int) * 31);
  40. int* word = malloc(sizeof(int) * 31);
  41. // int input[30][30];
  42. // int word[30];
  43. int  wordsizes [31];
  44. int words = 0;
  45.  
  46.   int c;
  47.   while ((c = getchar ()) != EOF)
  48.     {
  49.       if (isspace (c) != 0)
  50.     {
  51. words++;
  52. wordsizes[counter]=wordlength;
  53. counter++;
  54.       if (lwlm + wordlength > 30)
  55.         {
  56.          
  57.  useprinter(input, word, wordsizes,words);
  58.   words = 0;
  59.   counter = 0;
  60.   wordlength = 0;
  61.   lwlm = 0;         //last word length marker (just too long to ues everywhere)
  62.   inputlength = 0;
  63. for(int i=0;i<31;i++){
  64. wordsizes[i]=0;
  65. }
  66.  
  67.         }
  68.       input[words] = word;
  69.       wordsizes[words] = wordlength;
  70.       lwlm = lwlm + wordlength;
  71.     }
  72.  
  73.  
  74.       else
  75.     {
  76.     word[counter+1] = c;
  77.      wordlength++;
  78.      if (wordlength >= 30)
  79.         {
  80.                   useprinter(input, word, wordsizes,words);
  81.           words = 0;
  82.   counter = 0;
  83.   wordlength = 0;
  84.   lwlm = 0;         //last word length marker (just too long to ues everywhere)
  85.   inputlength = 0;
  86. for(int i=0;i<31;i++){
  87. wordsizes[i]=0;
  88. }
  89.         }
  90.     }
  91.  
  92.  
  93.     }
  94. free(input);
  95. free(word);
  96.  
  97.   return EXIT_SUCCESS;
  98. }
Add Comment
Please, Sign In to add comment