Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void print(char * pointer_array[][2], int linelen) {
- int length = 0, word_count = 1;
- const char punctuation[] = ".!?";
- *(pointer_array[0][0]) = toupper(*(pointer_array[0][0]));
- printf("\n%s", pointer_array[0][0]);
- length += strlen(pointer_array[0][0]);
- *(pointer_array[0][0]) = tolower(*(pointer_array[0][0]));
- if (pointer_array[word_count - 1][1] != NULL) {
- *(pointer_array[0][1]) = toupper( * (pointer_array[0][1]));
- printf(" (%s)", pointer_array[0][1]);
- length += strlen(pointer_array[0][1]) + 3;
- *(pointer_array[0][1]) = tolower( * (pointer_array[0][1]));
- }
- do {
- /* If the length of the line is over linelen, print word on line below */
- if (length + strlen(pointer_array[word_count][0]) >= linelen) {
- /* If there is a punctuation mark before line change, switch to uppercase for first letter */
- if (strstr(punctuation, pointer_array[word_count - 1][0]) != NULL) {
- *(pointer_array[word_count][0]) = toupper( * (pointer_array[word_count][0]));
- printf("\n%s", pointer_array[word_count][0]);
- length = strlen(pointer_array[word_count][0]);
- *(pointer_array[word_count][0]) = tolower( * (pointer_array[word_count][0]));
- word_count++;
- }
- /* Print word in new line */
- else {
- printf("\n%s", pointer_array[word_count][0]);
- length = strlen(pointer_array[word_count][0]);
- word_count++;
- }
- }
- /* If previous word is punctuation mark, switch to uppercase for first letter */
- else if (strstr(punctuation, pointer_array[word_count - 1][0]) != NULL) {
- *(pointer_array[word_count][0]) = toupper( * (pointer_array[word_count][0]));
- printf(" %s", pointer_array[word_count][0]);
- length += strlen(pointer_array[word_count][0]) + 1;
- *(pointer_array[word_count][0]) = tolower( * (pointer_array[word_count][0]));
- word_count++;
- }
- /* Print word */
- else {
- printf(" %s", pointer_array[word_count][0]);
- length += strlen(pointer_array[word_count][0]) + 1;
- word_count++;
- }
- /* Print synonyms if they are found*/
- if (pointer_array[word_count - 1][1] != NULL) {
- if (length + strlen(pointer_array[word_count - 1][1]) + 2 >= linelen) {
- /* If there is a punctuation mark before line change, switch to uppercase for first letter */
- if (strstr(punctuation, pointer_array[word_count - 2][0]) != NULL) {
- *(pointer_array[word_count - 1][1]) = toupper( * (pointer_array[word_count - 1][1]));
- printf("\n(%s)", pointer_array[word_count - 1][1]);
- length = strlen(pointer_array[word_count - 1][1]) + 2;
- *(pointer_array[word_count - 1][1]) = tolower( * (pointer_array[word_count - 1][1]));
- }
- /* Print word in new line */
- else {
- printf("\n(%s)", pointer_array[word_count - 1][1]);
- length = strlen(pointer_array[word_count - 1][1]) + 2;
- }
- }
- /* If previous word is punctuation mark, switch to uppercase for first letter */
- else if (strstr(punctuation, pointer_array[word_count - 2][0]) != NULL) {
- *(pointer_array[word_count - 1][1]) = toupper( * (pointer_array[word_count - 1][1]));
- printf(" (%s)", pointer_array[word_count - 1][1]);
- length += strlen(pointer_array[word_count - 1][1]) + 3;
- *(pointer_array[word_count - 1][1]) = tolower( * (pointer_array[word_count - 1][1]));
- }
- /* Print word */
- else {
- printf(" (%s)", pointer_array[word_count - 1][1]);
- length += strlen(pointer_array[word_count - 1][1]) + 3;
- }
- }
- } while (pointer_array[word_count][0] != NULL && word_count < MAX_WORDS);
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement