How do I read from file and print one byte at a time? Then remove the spaces and puctuations. Then store the words in a character array

32 views Asked by At

Code:

#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>       
#include <string.h>
#include <stdlib.h>

#define WM 15


int main()                 {
    int i=0,j=0,k=0,n, counter2, counter1, low, high, mid;

char sort, dummy, quit;
int a, GotBack, count, Got, innerCount;
bool DEBUG;
char temp[WM]; 
a = 0;
char* line[a][255];
char* search[a];
char* words[a];
long filelen;
char *buffer;
int buff;

FILE* Cprograms;

Cprograms = fopen("finalread.c", "r");

printf("Words in from the paragarph:"); 


    fseek(Cprograms, 0, SEEK_END);          
    filelen = ftell(Cprograms);            
    rewind(Cprograms);                      
    buffer = (char *)malloc((filelen+1)*sizeof(char)); 

    for(i = 0; i < filelen; i++) {
       
       fread(buffer+i, 1, 1, Cprograms); 
    
     }


     

    printf("File len: %d\n", filelen);
    printf("%s\n",*&buffer);
   

fclose(Cprograms); 
    return 0;
}

Output:

Words in from the paragarph:File len: 559
To be, or not to be, that is the question:
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune,
Or to take arms against a sea of troubles
And by opposing end them. To die, to sleep,
No more; and by a sleep to say we end
The heart-ache and the thousand natural shocks
That flesh is heir to: 'tis a consummation
Devoutly to be wish'd. To die, to sleep;
To sleep, perchance to dream, ay, there's the rub:
For in that sleep of death what dreams may come,
When we have shuffled off this mortal coil,
Must give us pause☻☺♥►☻☺♥ ☻☺♥ ☻←┌yç╧‼

I want the code to read only one byte at a time. Then I need the code to split the one-byte buffer into words and remove punctuation and make them lowercase and store them. Like char *words[] = { "to", "be", "or" }. I want it in a loop so each time it reads one byte does everything and goes back to start again.

For example, if this stored in the file "To be, or not to be, that is the question:" I'll need the code to first read "To Be, or" which is a byte Then print "To Be, or" Then remover spaces and puctuations and divde them by words and make them lower case like "to", "be", "or. Then store them in an array. Then goes back to read "not to be,"

Thanks in advance

0

There are 0 answers