So I am taking in a text file like so:
Hello. This is my test! I need to print sentences.
Can I do it? Any help is welcomed. Thanks!
And I am trying for output:
1. Hello.
2. This is my test!
3. I need to print sentences.
4. Can I do it?
...and so on....
Here is what I have written so far:
#include <stdio.h>
#include <stdlib.h>
main() {
int storage[50];
int i = 0 ;
int linecount = 1 ;
char c;
for (;;) {
c=getchar();
if(c == '\n'){
c == '\0';}
storage[i] = c;
i++;
if (c == '.' || c == '!' || c == '?') {
int j ;
printf("%d. ", linecount++);
for (j = 0; j < i; j++) {
printf("%c", storage[j]); }
i = 0 ;
printf("\n");
}
}
}
And it results with output:
1. Hello.
2. This is my test!
3. I need to print sentences.
4.
Can I do it?
5. Any help is welcomed.
6. Thanks!
My first issue is that it prints a '\n' for line 4, I thought that my code:
if(c == '\n'){
c == '\0';}
Would take care of this, but that is not the case.
My second issue is that it adds an extra space char after the first record. I know this is because I use the print statement:
"%d. "
and also the beginning of the sentences have a space to separate from last sentence but I am unsure on how to fix this issue. Any help would be great! Thanks! -qorz