Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8704899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:13:34+00:00 2026-06-13T03:13:34+00:00

Im trying to make a simple encryption program, nothing mathematical or so but to

  • 0

Im trying to make a simple encryption program, nothing mathematical or so but to go further I need to know what causes the segmentation fault in my program. I have tried to simplify my code..

char *
createAlfabeth(void)
{
    char * alfa = NULL;
    strcpy(alfa, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    int i, j=1, k=0;

    for(i=0; i<(sizeof(alfa)/sizeof(char)); i++, j+=3)
    {
        if(j>25)
        {
            j=1+(k++);
        }
        swap(alfa, i, j);
     }

     return alfa;
}

char *
codificator(char *mess, const char *alfa)
{
     int key[]=PRIVATE_KEY;
     char *newmess=NULL;
     int i, j;
     for(i=0, j=0; mess[i]!='\0'; i++, j++)
     {
          if(j>(sizeof(key)/sizeof(key[0])))
          {
               j=0;
           }
      newmess[i]=alfa[i+key[j]];
     }
     return newmess;
 }

 int
 main(void)
 {
     char *alfa=crearAlfabeto();
     printf("write your message :\n");
     char message[20];
     scanf("%s", message);
     char *codified=codificator(message, alfa);
     printf("The codified message is: %s \n", codified);    
     return 0;
 }

SOLVED: POST MEMORANDUM

I solved the problem with the recommendations by ouah and askmish below (thanks to both). And for you people googling to this answer, I want to say that this problem has to do with the heap handling. As I did not store enough space for the strings that I declared later or initialized there was not enough memory allocated to them.

This is was the malloc, realloc, calloc (and free) functions purpose is to handle. The segmentation fault comes from that I tried to move beyond the allocated memory for the data segment in the code. Every program allocated memory for the code (code segment), and data (data segment) and by not telling explicitly in c how much you are going to store in data segment you get this error. This is my understanding of what I have read, if someone with more insight wants to comment on this please do..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:13:35+00:00Added an answer on June 13, 2026 at 3:13 am
     char * alfa = NULL;
     strcpy(alfa, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    

    You need to allocate memory for your array object.

    For example:

     char *alfa = malloc(sizeof "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
     /* check that malloc succeeds here */
     strcpy(alfa, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make simple minesweeper game in python, but have one problem. I have
I am trying to make simple testing but failed because I have no clue
I'm trying to make a simple encryption program with C. My aim is to
Trying to make a simple program to catalogue books. Something like this, for example:
Trying to make a simple program to catalogue books. Something like this, for example:
I'm trying to make simple many-to-one association, using NHibernate.. I have class Recruit with
I am trying to make a simple resource dictionary for styles but the Background
I am trying to make simple mysql select query, I have 3 tables post:
I trying to make a simple image gallery, where I have several radio button
Im trying to make a simple downloader, but i cant make it to update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.