Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Segmentation fault in C code

Status
Not open for further replies.

ranayehya

Junior Member level 3
Joined
Apr 13, 2018
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
203
Hello!
I want to concatenate 2 unsigned char (temp and counter) contain hexadecimal numbers and store them in another variable (after) but this code ives me segmentation fault. Could someone help me?
Thanks..
Code:
#include<stdio.h>
void concat()
{
    //unsigned char state[4][4];
    unsigned char temp[8] = {0x00  ,0x01  ,0x02  ,0x03  ,0x04  ,0x05  ,0x06,0x07};
    unsigned char i, j;
    unsigned char after[16] ={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
    unsigned char counter[8]  = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
    // calculate the length of string s1
    // and store it in i
    for(i = 0; i <= 7; i++)
    {
        after[i] = temp[i];
    }
    for(i = 0; i <= 7; i++)
    {
        after[8+i] = temp[i];
    }
    for(i = 0; i <= 15; i++)
    {
        printf("%s\n", after[i]);
    }
   /* for(i=0;i<4;i++)
    {
        for(j=0;j<4;j++)
        {
            state[j][i] = counter[i*4 + j];
        }
    }*/
}
int main()
{
    concat();
    return 0;
}
 

couter have size 8 bytes, but you exceed it with i = 3, j = 3 => i * 4 + j = 15
replace counter with 'after'
 

Hello, Easyrider83!
This piece of code is a comment. It is my bad that I did not delete it. My apologizes.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top