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

  • Home
  • SEARCH
  • 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 6691215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:43:33+00:00 2026-05-26T05:43:33+00:00

I have this code: int main(){ char vector[52]; char i; /* initialize the vector

  • 0

I have this code:

int main(){

  char vector[52];
  char i;

  /* initialize the vector */
  for (i ='a'; i < 'z'; i++){
    vector[i] = i - 'a' + 1;
  } 
  // vector is like vector['a'] = 1, vector['b'] = 2 .. vector['z'] = 26


  for (i ='A'; i <= 'Z'; i++){
    vector[i] = i - 'A' + 27;
  }
  // vector is like vector['A'] = 27, vector['B'] = 28 .. vector['z'] = 52

  for (i ='a'; i <= 'z'; i++){
    printf("letter %c : %d \n", i, vector[i]);
  } 

  for (i ='A'; i <= 'Z'; i++){
    printf("letter %c : %d \n", i, vector[i]);
  }

  return 0;
}

Output :

letter a : 1 
letter b : 2 
letter c : 3 
letter d : 4 
letter e : 5 
letter f : 6 
letter g : 7 
letter h : 8 
letter i : 9 
letter j : 10 
letter k : 11 
letter l : 12 
letter m : 13 
letter n : 14 
letter o : 15 
letter p : 16 
letter q : 17 
letter r : 18 
letter s : 19 
letter t : 20 
letter u : 21 
letter v : 22 
letter w : 23 
letter x : 24 
letter y : 25 
letter z : 0 
letter A : 27 
letter B : 28 
letter C : 29 
letter D : 30 
letter E : 31 
letter F : 32 
letter G : 33 
letter H : 34 
letter I : 35 
letter J : 36 
letter K : 37 
letter L : 38 
letter M : 39 
letter N : 40 
letter O : 41 
letter P : 42 
letter Q : 43 
letter R : 44 
letter S : 45 
letter T : 46 
letter U : 47 
letter V : 48 
letter W : 49 
letter X : 50 
letter Y : 51 
letter Z : 52 
*** stack smashing detected ***: ./a.out terminated
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(__fortify_fail+0x50)[0xc25df0]
/lib/i386-linux-gnu/libc.so.6(+0xe5d9a)[0xc25d9a]
./a.out[0x8048547]
[0x343332]
======= Memory map: ========
00110000-0012a000 r-xp 00000000 08:01 131939     /lib/i386-linux-gnu/libgcc_s.so.1
0012a000-0012b000 r--p 00019000 08:01 131939     /lib/i386-linux-gnu/libgcc_s.so.1
0012b000-0012c000 rw-p 0001a000 08:01 131939     /lib/i386-linux-gnu/libgcc_s.so.1
00a19000-00a1a000 r-xp 00000000 00:00 0          [vdso]
00aa4000-00ac0000 r-xp 00000000 08:01 131898     /lib/i386-linux-gnu/ld-2.13.so
00ac0000-00ac1000 r--p 0001b000 08:01 131898     /lib/i386-linux-gnu/ld-2.13.so
00ac1000-00ac2000 rw-p 0001c000 08:01 131898     /lib/i386-linux-gnu/ld-2.13.so
00b40000-00c9a000 r-xp 00000000 08:01 131911     /lib/i386-linux-gnu/libc-2.13.so
00c9a000-00c9b000 ---p 0015a000 08:01 131911     /lib/i386-linux-gnu/libc-2.13.so
00c9b000-00c9d000 r--p 0015a000 08:01 131911     /lib/i386-linux-gnu/libc-2.13.so
00c9d000-00c9e000 rw-p 0015c000 08:01 131911     /lib/i386-linux-gnu/libc-2.13.so
00c9e000-00ca1000 rw-p 00000000 00:00 0 
08048000-08049000 r-xp 00000000 08:01 40062      /home/valter/Documents/Complexidade/recursivo/a.out
08049000-0804a000 r--p 00000000 08:01 40062      /home/valter/Documents/Complexidade/recursivo/a.out
0804a000-0804b000 rw-p 00001000 08:01 40062      /home/valter/Documents/Complexidade/recursivo/a.out
0846f000-08490000 rw-p 00000000 00:00 0          [heap]
b7772000-b7773000 rw-p 00000000 00:00 0 
b7782000-b7785000 rw-p 00000000 00:00 0 
bfa50000-bfa71000 rw-p 00000000 00:00 0          [stack]
Aborted

I don’t understand why is giving this error message.
I should have a vector like this :

vector['a'] = 0, vector['b'] = 1,  .., vector['z'] = 26, vector['A'] = 27, vector['B'] = 28, .., vector['Z'] = 52

I understand that I have this vector but the error came with it.
How solve this problem ?

  • 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-05-26T05:43:34+00:00Added an answer on May 26, 2026 at 5:43 am

    Because ‘Z’ is not equal to ‘z’.

    ‘Z’ is equal to 90 and your vector only has 52 elements. Your highest index is 51 so you are basically going out of bounds!

    For example when you are doing this

      for (i ='A'; i <= 'Z'; i++)
      {
        vector[i] = i - 'A' + 27;
      }
    

    This is what your first iteration looks like:

    vector[65] = 65 - 65 + 27; // <-- Wrong index !
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
I have a code that looks like this: int main () { fstream file;
I have this code in C: int main(){ char a[10]; _asm{ mov DWORD PTR[a],eax;}
i have this piece of code int main() { char a[100]; a[0]='a'; a[1]='b'; fun(a[0]);
I have this code: #include <iostream> #include <mp4.h> int main (int argc, char *
I have the following code: int main() { char *sPPhrase[51]; /* Input */ printf(Enter
I have this code struct Student { char name[48]; float grade; int marks[10,5]; char
Hi, i'm have this code for initialize my class. - (id)initWithSize:(int)size { self =
Suppose I have this (C++ or maybe C) code: vector<int> my_vector; for (int i
I have this code: void PrintMainParameters(int n, char* array[]) { int i = 0;

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.