Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char passage[5000][20];
- int wordnum;
- char *getword(int x);
- void readTextFile() {
- FILE *fp;
- //char buffer;
- fp = fopen("data.txt", "r");
- int i=1,j=1;
- while (fscanf(fp,"%c", &passage[i][j]) != EOF){
- if (passage[i][j] == '.' || passage[i][j] == ',' || passage[i][j] == '!' || passage[i][j] == '?' || passage[i][j] == ' '|| passage[i][j] == ';'){
- i++;
- j=1;
- }else{
- j++;
- }
- }
- fclose(fp);
- wordnum = i;
- }
- int main(){
- readTextFile();
- int i;
- for (i=0;i<20;i++){
- char *word = getword(i);
- if (strlen(word)<= 0)
- break;
- printf("%dn", strcmp(word,"am"));
- printf("word[%d]=%s", i, word);
- printf("length = %i nn", strlen(word));
- }
- }
- char *getword(int i){
- static char s[20];
- int j=0;
- while (passage[i][j] != '