Error in code blocks and shows segmentation fault in online compilation?

The following code causes code blocks to stop. It is displayed as some problem caused the program to close. when i tried online compilation it showes as segmentation fault(core dumped). I couldn't find out what it is!

//Hash table

#include<stdio.h>
#include<string.h>

int main()
{
    int option,i,key;
    char value[10], hashtab[10][10];

    for(i=0;i<10;i++)
    {
        strcpy(hashtab[i],'\0');
    }

    printf("\nEnter 1-Insert ANY-Exit");
    scanf("%d",&option);
    while(option==1)
    {
        printf("\nEnter the Value: ");
        scanf("%s",value);
        key=keygen(value);
        strcpy(hashtab[key],value);
     }

    for(i=0;option==2&&i<10;i++)
    {
        printf("\n%s",hashtab[i]);
    }
}

int keygen(char *value)
{
    int i,key=0;
    for(i=0;i<strlen(value);i++)
    {
        key=key+value[i];
    }
    return key;
}

Answers


strcpy used in the for loop should be arguments as below,

  char *strcpy(char *dest, const char *src);

Ideally the second argument passed should be the string pointed to by src.

Making it to, strcpy(hashtab[i], "\0"); should work.


Need Your Help

How to parse AREAS() using poi formula parser

java function apache-poi

How to parse the AREAS(B5:B6, C5:C8) Function using APACHE POI formula parser.

Special chars in Amazon S3 keys?

amazon-s3

Is it possible to have special characters like åäö in the key? If i urlencode the key before storing it works, but i cant really find a way to access the object. If i write åäö in the url i get acc...