Guest User

Untitled

a guest
Oct 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char passage[5000][20];
  6. int wordnum;
  7.  
  8. char *getword(int x);
  9.  
  10. void readTextFile() {
  11. FILE *fp;
  12. //char buffer;
  13.  
  14. fp = fopen("data.txt", "r");
  15.  
  16. int i=1,j=1;
  17. while (fscanf(fp,"%c", &passage[i][j]) != EOF){
  18. if (passage[i][j] == '.' || passage[i][j] == ',' || passage[i][j] == '!' || passage[i][j] == '?' || passage[i][j] == ' '|| passage[i][j] == ';'){
  19. i++;
  20. j=1;
  21. }else{
  22. j++;
  23. }
  24. }
  25. fclose(fp);
  26. wordnum = i;
  27. }
  28.  
  29. int main(){
  30. readTextFile();
  31. int i;
  32. for (i=0;i<20;i++){
  33. char *word = getword(i);
  34. if (strlen(word)<= 0)
  35. break;
  36.  
  37. printf("%dn", strcmp(word,"am"));
  38. printf("word[%d]=%s", i, word);
  39. printf("length = %i nn", strlen(word));
  40. }
  41.  
  42.  
  43.  
  44.  
  45. }
  46.  
  47. char *getword(int i){
  48. static char s[20];
  49. int j=0;
  50. while (passage[i][j] != ''){
  51. s[j]=passage[i][j];
  52. j++;
  53. }
  54. s[j]='';
  55. return s;
  56. }
Add Comment
Please, Sign In to add comment