1

Topic: In studio works, and for consoles takes off ()

The program on Si for count how many time each word meets in the text, usage . It is written in VS 2013 at start by a local debugger works, and at start from the console takes off.
[spoiler hash.c]

#include "hashhead.h"
unsigned char hash (const char *str)
{
unsigned int hash = 0;
for (; *str; str ++)
hash = (hash * 1664525) + (unsigned char) (*str) + 1013904223;
return hash>> 24;
}
void insert (struct node *a [], char *word) {
unsigned char index;
struct node *n, *p;
p = findNode (word, a);
if (p == NULL)
{
index = hash (word);
n = (node *) malloc (sizeof (node *));
strcpy_s (n-> word, 11, word);
n-> next = a [index];
n-> count = 1;
a [index] = n;
}
else {
p-> count ++;
}
}
struct node *findNode (char *word, node* a [255]) {
node *p;
p = a [hash (word)];
while (p && strcmp (p-> word, word))
p = p-> next;
return p;
}
void prntable (struct node *a [255]) {
int i;
node *p;
for (i = 0; i <256; i ++) {
p = a [i];
while (p) {
printf ("%s %d\n", p-> word, p-> count);
p = p-> next;
}
}
}
void prntable_f (struct node *a [255], FILE *f) {
int i;
node *p;
for (i = 0; i <256; i ++) {
p = a [i];
while (p) {
fprintf (f, "%s %d\n", p-> word, p-> count);
p = p-> next;
}
}
}
int poscinstr (char *str, char c)
{
unsigned int i;
for (i = 0; i <strlen (str); i ++) {
if (str [i] == c) {
return i;
}
}
return-1;
}

[/spoiler]
[spoiler hashhead.h]

#ifndef HASHHEAD_H
#define HASHHEAD_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
void insert (struct node *a [], char *word);
unsigned char hash (const char *str);
void prntable (struct node *a [255]);
void prntable_f (struct node *a [255], FILE *f);
struct node *findNode (char *word, struct node *a []);
typedef struct node
{
char word [11];
int count;
struct node *next;
}node;
int poscinstr (char *str, char c);
#endif/*HASHHEAD_H*/

[/spoiler]
[spoiler hashtest.c]

#include "hashhead.h"
void main (int argc, char *argv []) {
node *a [256];
FILE *f = stdout;
FILE *fi = stdin;
char str [2000];
char word_t [50];
char *estr, *letters, *symbols;
unsigned int j;
int k;
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for (j = 0; j <256; j ++) {
a [j] = (node *) malloc (sizeof (node *));
a [j] = NULL;
}
switch (argc) {
case 1:
printf ("hashtable, version 0.0.0.1 x86\n");
printf ("Usage: Input an text file\n");
printf ("hashtable.exe-in filename-o |-out filename\n");
printf ("Output: file containing amount of each word\n");
break;
case 2:
if ((strcmp (argv [1], "-help") == 0) || (strcmp (argv [1], "-HELP") == 0)) {
printf ("hashtable, version 0.0.0.1 x86\n");
printf ("Usage: Input an text file\n");
printf ("hashtable.exe-in filename-o |-out filename\n");
printf ("Output: file containing amount of each word\n");
break;
}
case 3:
if (strcmp (argv [1], "-in") == 0) {
if (fopen_s (&fi, argv [2], "r") == 0)
{
while (1) {
estr = fgets (str, 2000, fi);
if (estr == NULL)
{
if (feof (fi)! = 0)
{
fclose (fi);
break;
}
else
{
printf ("\nFile read error\n");
break;
}
}
j = 0;
while ((poscinstr (letters, str [j]) <0) && (j <strlen (str))) {
j ++;
}
k = 0;
while (j <strlen (str)) {
word_t [k] = str [j];
k ++;
j ++;
if (poscinstr (letters, str [j]) <0) {
word_t [k] = '\0 ';
if ((strlen (word_t) <11) && (strlen (word_t)> 0)) {
insert (a, word_t);
}
k = 0;
while ((poscinstr (letters, str [j]) <0) && (j <strlen (str))) {
j ++;
}
}
}
word_t [k] = '\0 ';
if ((strlen (word_t) <11) && (strlen (word_t)> 0)) {
insert (a, word_t);
}
}
prntable (a);
getchar ();
break;
}
else {
printf ("Input file not opened.");
getchar ();
break;
}
}
case 5:
if ((strcmp (argv [1], "-in") == 0) && ((strcmp (argv [3], "-o") == 0) || (strcmp (argv [3], "-out") == 0))) {
if (fopen_s (&fi, argv [2], "r") == 0)
{
while (1) {
estr = fgets (str, 2000, fi);
if (estr == NULL)
{
if (feof (fi)! = 0)
{
fclose (fi);
break;
}
else
{
printf ("\nFile read error\n");
break;
}
}
j = 0;
while ((poscinstr (letters, str [j]) <0) && (j <strlen (str))) {
j ++;
}
k = 0;
while (j <strlen (str)) {
word_t [k] = str [j];
k ++;
j ++;
if (poscinstr (letters, str [j]) <0) {
word_t [k] = '\0 ';
if ((strlen (word_t) <11) && (strlen (word_t)> 0)) {
insert (a, word_t);
}
k = 0;
while ((poscinstr (letters, str [j]) <0) && (j <strlen (str))) {
j ++;
}
}
}
word_t [k] = '\0 ';
if ((strlen (word_t) <11) && (strlen (word_t)> 0)) {
insert (a, word_t);
}
}
if (fopen_s (&f, argv [4], "w") == 0)
{
prntable_f (a, f);
fclose (f);
}
else {
printf ("Output file not opened.");
getchar ();
break;
}
break;
}
else {
printf ("Input file not opened.");
getchar ();
break;
}
}
}
return;
}

[/spoiler]

2

Re: In studio works, and for consoles takes off ()

vlladimir wrote:

and at start from the console takes off

And it, it is casual so, thus does not write "  ", including the exact
The reason and error place, and as call stack, led to it?.

3

Re: In studio works, and for consoles takes off ()

Dimitry Sibiryakov, Is not present simply all (program operation Is stopped) takes off also

4

Re: In studio works, and for consoles takes off ()

vlladimir wrote:

Is not present simply all takes off also

not surprisingly

void prntable (struct node *a [>>> 255 <<<]) {
int i;
node *p;
for (i = 0; i <>>> 256 <<<; i ++) {
p = a [i];
while (p) {
printf ("%s %d\n", p-> word, p-> count);
p = p-> next;
}
}
}

an output for array limits always come to an end not pleasantly

5

Re: In studio works, and for consoles takes off ()

"That people only do not do not to use..." wc
Or here so " wc and that will be wc" smile

6

Re: In studio works, and for consoles takes off ()

7

Re: In studio works, and for consoles takes off ()

Peter Sedov, Thanks huge!
[quote =] n = (node *) malloc (sizeof (node));

Business was this line, after editing all earned, well and something else corrected by your councils, once again thanks!!!