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 7995185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:20:03+00:00 2026-06-04T14:20:03+00:00

I have this small exercise that I am trying to finish, but I get

  • 0

I have this small exercise that I am trying to finish, but I get an error that I’ve never seen before. It doesn’t even seem logical to me:

Unhandled exception at 0x0003191a in oop244_a1.exe: 0xC0000005: Access violation reading location 0x003134d4.

Here is the program code:
The function is at the button (bit_to_ascii), that is where the problem is occuring. I’ve tried debugging the program, and it seems that the variable ‘clen’ gets changed for some reason, to a unreasonably high number (100000+), when its supposed to be 950 characters for that loop

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

#define LINES 5

/* assignment #1 function prototype */
int bit_to_ascii(const char [ ], char [ ]);

int main( ) {

   const char *core_data[ ] = {
"0", /* should insert the null byte '\0' only */

"01010111 This sequence contains the letter 'W'       " /*  87 = 'W' */
"      r5 0 #! 1 1 gP 0 f66-:] 0 [ } 1 v4t^ 0 1 n>?:77" /* 101 = 'e' */
" junk ^*@&#^% 0110  more junk }{r;,<> 1100         2x" /* 108 = 'l' */
"                  0    1       1     0 0          011" /*  99 = 'c' */
"0  ^%jh  1 ]{) OVR 1 - 0 _! 9 + 1  118Y z(x pM1      " /* 111 = 'o' */
"This next group of 8 should be SKP skipped! 11111111 " /* skipped */
"*&^! 0  1  1  0 1     1 0     128673kjshd:L<    2938 " /* 109 = 'm' */
"      r5 0 #! 1 1 gP 0 f66-:] 0 [ } 1 v4t^ 0 1 n>?:77" /* 101 = 'e' */
"#!/bin/bash 00  1 00 00 0 g^b-ps 6@&^%               " /*  32 = ' ' */
"01010100 This sequence contains the letter 'T'       " /*  84 = 'T' */
"0  ^%jh  1 ]{) OVR 1 - 0 _! 9 + 1  118Y z(x pM1      " /* 111 = 'o' */
"#!/bin/bash 00  1 00 00 0 g^b-ps 6@&^%               " /*  32 = ' ' */
"---repeat--->0 1 0 0 1 1 1 1<------------RPT2--------" /*  79 = 'O' */
"0 1 0 1 0bbavac9872962  000&*************************" /*  80 = 'P' */
"a0b0c1d1e0f0g1h0ijklmnopqrstuvwxyz*******************" /*  50 = '2' */
"00fg333                                110100>>>>>>>>" /*  52 = '4' */
"00fg333                                110100>>>>>>>>" /*  52 = '4' */
"                     0000                            ",/*  0 = '\0' */

"00011110 This char should not be inserted!           " /*  30 cntrl */
" 00011111 This char should not be inserted!          " /*  31 cntrl */
"  00100000                                           " /*  32 = ' ' */
"   00100001                                          " /*  33 = '!' */
"    00100010                                         " /*  34 = '"' */
"     00100011                                        " /*  35 = '#' */
"      00100100                                       " /*  36 = '$' */
"       00100101                                      " /*  37 = '%' */
"        00100110                                     " /*  38 = '&' */
"         00100111                                    " /*  39 = ''' */
"          00101000                                   " /*  40 = '(' */
"           00101001                                  " /*  41 = ')' */
"            00101010                                 " /*  42 = '*' */
"             00101011                                " /*  43 = '+' */
"              00101100                               " /*  44 = ',' */
"               00101101                              " /*  45 = '-' */
"                00101110                             " /*  46 = '.' */
"                 00101111                            " /*  47 = '/' */
"                  00110000                           " /*  48 = '0' */
"                   00110001                          " /*  49 = '1' */
"                    00110010                         " /*  50 = '2' */
"                     00110011                        " /*  51 = '3' */
"                      00110100                       " /*  52 = '4' */
"                       00110101                      " /*  53 = '5' */
"                        00110110                     " /*  54 = '6' */
"                         00110111                    " /*  55 = '7' */
"                          00111000                   " /*  56 = '8' */
"                           00111001                  " /*  57 = '9' */
"                            00111010                 " /*  58 = ':' */
"                             00111011                " /*  59 = ';' */
"                              00111100               " /*  60 = '<' */
"                               00111101              " /*  61 = '=' */
"                                00111110             " /*  62 = '>' */
"                                 00111111            " /*  63 = '?' */
"                                  01000000           " /*  64 = '@' */
"                                   00000000          ",/*   0 = '\0'*/

"                                    01000001         " /*  65 = 'A' */
"                                     01000010        " /*  66 = 'B' */
"                                      01000011       " /*  67 = 'C' */
"                                       01000100      " /*  68 = 'D' */
"                                        01000101     " /*  69 = 'E' */
"                                         01000110    " /*  70 = 'F' */
"                                          01000111   " /*  71 = 'G' */
"                                           01001000  " /*  72 = 'H' */
"                                            01001001 " /*  73 = 'I' */
"                                             01001010" /*  74 = 'J' */
"                                            01001011 " /*  75 = 'K' */
"                                           01001100  " /*  76 = 'L' */
"                                          01001101   " /*  77 = 'M' */
"                                         01001110    " /*  78 = 'N' */
"                                        01001111     " /*  79 = 'O' */
"                                       01010000      " /*  80 = 'P' */
"                                      01010001       " /*  81 = 'Q' */
"                                     01010010        " /*  82 = 'R' */
"                                    01010011         " /*  83 = 'S' */
"                                   01010100          " /*  84 = 'T' */
"                                  01010101           " /*  85 = 'U' */
"                                 01010110            " /*  86 = 'V' */
"                                01010111             " /*  87 = 'W' */
"                               01011000              " /*  88 = 'X' */
"                              01011001               " /*  89 = 'Y' */
"                             01011010                " /*  90 = 'Z' */
"                            01011011                 " /*  91 = '[' */
"                           01011100                  " /*  92 = '/' */
"                          01011101                   " /*  93 = ']' */
"                         01011110                    " /*  94 = '^' */
"                        01011111                     " /*  95 = '_' */
"                       01100000                      " /*  96 = '`' */
"                      00000000                       ",/*   0 = '\0'*/

"                     01100001                        " /*  97 = 'a' */
"                    01100010                         " /*  98 = 'b' */
"                   01100011                          " /*  99 = 'c' */
"                  01100100                           " /* 100 = 'd' */
"                 01100101                            " /* 101 = 'e' */
"                01100110                             " /* 102 = 'f' */
"               01100111                              " /* 103 = 'g' */
"              01101000                               " /* 104 = 'h' */
"             01101001                                " /* 105 = 'i' */
"            01101010                                 " /* 106 = 'j' */
"           01101011                                  " /* 107 = 'k' */
"          01101100                                   " /* 108 = 'l' */
"         01101101                                    " /* 109 = 'm' */
"        01101110                                     " /* 110 = 'n' */
"       01101111                                      " /* 111 = 'o' */
"      01110000                                       " /* 112 = 'p' */
"     01110001                                        " /* 113 = 'q' */
"    01110010                                         " /* 114 = 'r' */
"   01110011                                          " /* 115 = 's' */
"  01110100                                           " /* 116 = 't' */
" 01110101                                            " /* 117 = 'u' */
"01110110                                             " /* 118 = 'v' */
" 01110111                                            " /* 119 = 'w' */
"  01111000                                           " /* 120 = 'x' */
"   01111001                                          " /* 121 = 'y' */
"    01111010                                         " /* 122 = 'z' */
"     01111011                                        " /* 123 = '{' */
"      011111RPT10                                    " /* 124 = '|' */
"       01111101                                      " /* 125 = '}' */
"        00000000                                     " /*   0 = '\0'*/
};

   char phrase[41];
   char correct[LINES][41] = {
      "",
      "Welcome To OOP244",
      " !\"#$%&'()*+,-./0123456789:;<=>?@",
      "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`",
      "abcdefghijklmnopqrstuvwxyz{||||||||||}"
   };

   int rvalues[LINES] = { 1, 18, 34, 33, 39 }, i;
   int valid = 1, rc, err_code;

   for(i=0; i<LINES && valid; i++) {
      rc = bit_to_ascii(core_data[i], phrase);
      if(rc != rvalues[i] || strcmp(phrase, correct[i])) {
     printf("Failed on test... %d\n\n", i+1);
     valid = 0;
      }
      else {
     printf("Passed test %d...\n\n", i+1);
      }
      printf("Your string ----------> '%s'\n", phrase);
      printf("Actual string --------> '%s'\n", correct[i]);
      printf("Your return value ----> %d\n", rc);
      printf("Actual return value --> %d\n", rvalues[i]);
      printf("Press the ENTER key to continue...");
      getchar( );
   }
   if(valid) {
      printf("\nCongratualtions!!! You passed all tests.\n");
      printf("You may hand in your assignment.\n");
   }
   else {
      printf("\nYou correctly sequenced %d/5 data blocks...\n", i-1);
      printf("Your program still needs some work!\n");
      printf("Keep at it!\n\n");
   }
   getchar();
   return 0;
}

int bit_to_ascii(const char core[], char data[]) {
    int clen = strlen(core);
    int dlen = strlen(data);
    char bits[8] = {0,0,0,0,0,0,0,0};
    int bit_idx = 0;
    int i = 0;
    int dcount = 0;

    printf("clen: %d\n", clen);

    for (i = 0; i < clen; i++) {
        if (core[i] == '0' || core[i] == '1') {
            bits[bit_idx++] = core[i];

            //printf("bit_idx: %d\n", bit_idx);
            //printf("clen: %d\n", clen);
            //printf("i+1: %d\n", i+1);

            if (bit_idx == 8 || ((i+1) >= clen)) {

                int power = 7;
                double dec = 0.0;
                int j;

                // fill in with zeroes
                for (j = bit_idx; j < 8; j++) {
                    bits[j] = 0;
                }

                // binary to decimal
                for (j = 0; j < 8; j++) {
                    if (bits[j] == '1') {
                        dec += pow((double)2, power--);
                    }
                }

                data[dcount++] = (int)dec;
            }
        }
    }

    return dcount;
}
  • 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-04T14:20:05+00:00Added an answer on June 4, 2026 at 2:20 pm

    I didn’t test it, but probably you have to set bit_idx to ‘0’ after reaching 8.

    If not, you will write out of the bits array and overwrite the stack. Probably the clen variable happens to be just there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this small application that I'm building as an exercise to learn the
I have this small problem with the DriveInfo Class. I know that the error
I have this small class called City that simply holds some information about a
I have this small PHP script that takes a POST variable and writes it
I have this small piece of code that basically takes a list and runs
In CodeIgniter I'm using a base CRUD My_model , but I have this small
I got this as home exercise but I have no clue how to solve
I have this small script that sorts the content of a text file #
I have this small script that shows a caption for a img when it
I have this small app that loads plugin type components that other users can

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.