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...
By Anonymous on the 9th of Feb 2010 11:41:21 PM
Download |
Raw |
Embed |
Report
#include <stdio.h>
#include <stdlib.h>
typedef struct wordc {
char *word;
int count;
struct wordc *next;
} node;
typedef struct linkedlist {
node *head;
} list;
struct list *wordstore[26];
int instorage(char *inword) {
node *nword;
list *wordlist;
int location = *inword - 97;
printf("%c %i %s %i \n", *inword
, *inword
, inword
, location
);
if (wordstore[location] == NULL) {
nword = malloc(sizeof(node));
wordlist = malloc(sizeof(list));
(*nword).word = inword;
(*nword).count = 0;
(*nword).next = NULL;
(*wordlist).head = nword;
wordstore[location] = (list *)wordlist;
}
return 0;
}
int main(int argc, char **argv) {
char *filename, *word;
FILE *fp, *fp2;
int char1, char2, inword = 0, length, accum = 0, x;
filename = argv[1];
fp = fopen(filename, "r");
fp2 = fopen(filename, "r");
if (fp == 0) {
printf("Could not open %s \n", filename
);
return 0;
}
char1 = fgetc(fp);
char2 = fgetc(fp2);
while (char1 != EOF) {
/*printf("%c %c %i %i Inword:%i \n", char1, char2, ftell(fp), ftell(fp2), inword);*/
if (inword == 1) {
if ((char2 > 64 && char2 < 91) || (char2 > 96 && char2 < 123)) {
char2 = fgetc(fp2);
} else {
length = ftell(fp2) - ftell(fp);
word = (char *)malloc(sizeof(char) * length + 1);
while (ftell(fp) != ftell(fp2)) {
if (char1 > 64 && char1 < 91) char1 = char1 + 32;
*(word + accum) = char1;
char1 = fgetc(fp);
accum++;
}
*(word + accum) = '\0';
printf("%s is the word\n", word
);
instorage((char *)word);
accum = 0;
inword = 0;
}
} else {
if ((char2 > 64 && char2 < 91) || (char2 > 96 && char2 < 123)) {
char2 = fgetc(fp2);
inword = 1;
} else {
char1 = fgetc(fp);
char2 = fgetc(fp2);
}
}
}
for (x =0; x < 26; x++) {
if (wordstore[x])
printf("%s \n", wordstore
[x
]->head.
word);
}
fclose(fp);
fclose(fp2);
return 0;
}
Submit a correction or amendment below.
Make A New Post