Recent Posts
None | 12 sec ago
C++ | 57 sec ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
Lua | 1 min ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Anonymous on the 9th of Feb 2010 11:41:21 PM Download | Raw | Embed | Report
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct wordc {
  5.         char *word;
  6.         int count;
  7.         struct wordc *next;
  8.         } node;
  9.        
  10. typedef struct linkedlist {
  11.         node *head;
  12.         } list;
  13.  
  14. struct list *wordstore[26];
  15.  
  16. int instorage(char *inword) {
  17.         node *nword;
  18.         list *wordlist;
  19.         int location = *inword - 97;
  20.         printf("%c %i %s %i \n", *inword, *inword, inword, location);
  21.         if (wordstore[location] == NULL) {
  22.                 nword = malloc(sizeof(node));
  23.                 wordlist = malloc(sizeof(list));
  24.                 (*nword).word = inword;
  25.                 (*nword).count = 0;
  26.                 (*nword).next = NULL;
  27.                 (*wordlist).head = nword;
  28.                 wordstore[location] = (list *)wordlist;
  29.         }
  30.         return 0;
  31. }
  32. int main(int argc, char **argv) {
  33.         char *filename, *word;
  34.         FILE *fp, *fp2;
  35.         int char1, char2, inword = 0, length, accum = 0, x;
  36.        
  37.         filename = argv[1];
  38.         fp = fopen(filename, "r");
  39.         fp2 = fopen(filename, "r");
  40.        
  41.         if (fp == 0) {
  42.                 printf("Could not open %s \n", filename);
  43.                 return 0;
  44.         }
  45.        
  46.         char1 = fgetc(fp);
  47.         char2 = fgetc(fp2);
  48.         while (char1 != EOF) {
  49.                 /*printf("%c %c %i %i Inword:%i \n", char1, char2, ftell(fp), ftell(fp2), inword);*/
  50.                 if (inword == 1) {
  51.                         if ((char2 > 64 && char2 < 91) || (char2 > 96 && char2 < 123)) {
  52.                                 char2 = fgetc(fp2);
  53.                         } else {
  54.                                 length = ftell(fp2) - ftell(fp);
  55.                                 word = (char *)malloc(sizeof(char) * length + 1);
  56.                                 while (ftell(fp) != ftell(fp2)) {
  57.                                         if (char1 > 64 && char1 < 91) char1 = char1 + 32;
  58.                                         *(word + accum) = char1;
  59.                                         char1 = fgetc(fp);
  60.                                         accum++;
  61.                                 }
  62.                                 *(word + accum) = '\0';
  63.                                 printf("%s is the word\n", word);
  64.                                 instorage((char *)word);
  65.                                 accum = 0;
  66.                                 inword = 0;
  67.                         }
  68.                 } else {
  69.                         if ((char2 > 64 && char2 < 91) || (char2 > 96 && char2 < 123)) {
  70.                                 char2 = fgetc(fp2);
  71.                                 inword = 1;
  72.                         } else {
  73.                                 char1 = fgetc(fp);
  74.                                 char2 = fgetc(fp2);
  75.                         }
  76.                 }
  77.         }
  78.        
  79.         for (x =0; x < 26; x++) {
  80.                 if (wordstore[x])
  81.                         printf("%s \n", wordstore[x]->head.word);
  82.         }
  83.        
  84.         fclose(fp);
  85.         fclose(fp2);
  86.         return 0;
  87.         }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: