Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <ctype.h>
- static int counter = 0;
- static int wordlength = 0;
- static int lwlm = 0; //last word length marker (just too long to ues everywhere)
- static int inputlength = 0;
- void
- useprinter (int** input, int* word, int wordsizes[],int words)
- {
- printf("printing seems to be turning on");
- for (int i = 0; i < words; i++)
- {
- for (int j = 0; j < wordsizes[i]; j++)
- {
- // ISSUE PLACE printf ("%c", (*input+i)[j]);
- // ISSUE PLACE (*input+i)[j] = 0;
- //printf("q"); FOR TESTING
- }
- printf(" ");
- // wordsizes[i] = 0;
- // word[i] = 0;
- }
- printf ("\n");
- }
- int
- main (void)
- {
- int** input = malloc(sizeof(int) * 31);
- int* word = malloc(sizeof(int) * 31);
- // int input[30][30];
- // int word[30];
- int wordsizes [31];
- int words = 0;
- int c;
- while ((c = getchar ()) != EOF)
- {
- if (isspace (c) != 0)
- {
- words++;
- wordsizes[counter]=wordlength;
- counter++;
- if (lwlm + wordlength > 30)
- {
- useprinter(input, word, wordsizes,words);
- words = 0;
- counter = 0;
- wordlength = 0;
- lwlm = 0; //last word length marker (just too long to ues everywhere)
- inputlength = 0;
- for(int i=0;i<31;i++){
- wordsizes[i]=0;
- }
- }
- input[words] = word;
- wordsizes[words] = wordlength;
- lwlm = lwlm + wordlength;
- }
- else
- {
- word[counter+1] = c;
- wordlength++;
- if (wordlength >= 30)
- {
- useprinter(input, word, wordsizes,words);
- words = 0;
- counter = 0;
- wordlength = 0;
- lwlm = 0; //last word length marker (just too long to ues everywhere)
- inputlength = 0;
- for(int i=0;i<31;i++){
- wordsizes[i]=0;
- }
- }
- }
- }
- free(input);
- free(word);
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment