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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:54:32+00:00 2026-05-30T21:54:32+00:00

#include <time.h> int perm_table[255]; float rand_vectors[255][3]; initialize_random_numbers() { int i; float tmp[3], length; for

  • 0
#include <time.h>

int perm_table[255];
float rand_vectors[255][3];

initialize_random_numbers()
{
    int i;
    float tmp[3], length;
    for (i=0; i<255; i++)
    {
        perm_table[i] = rand() % 255;

        tmp[0] = (float)(rand() % 1000);
        tmp[1] = (float)(rand() % 1000);
        tmp[2] = (float)(rand() % 1000);

        printf("\n%i", i);

        memcpy(rand_vectors[i], tmp, sizeof(float)*3);
    }
}

Running this prints every number from 0 to 253 (on 255), before giving a Segmentation Fault.

Commenting out this line

perm_table[i] = rand() % 255;

removes the error.

I am completely beaten by this. Any help?

  • 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-30T21:54:33+00:00Added an answer on May 30, 2026 at 9:54 pm

    There is nothing wrong in this code for me.

    The segfault probably occurs after the function returns and not because of this function.

    The fact that the last number printed is 253 is because the stream is not flushed after
    printf("\n%i", i); and as the segfault occurs after the function, the stream never got flushed.

    By default, when connected to a terminal, stdout is line-buffered. To flush stdout either call fflush(stdout) or print a '\n' character.

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

Sidebar

Related Questions

I've used #include<stdlib> #include<time> using namespace std; srand((unsigned)time(0)); int n=(rand()>>8)%4; but what other random
Consider the following code which shows compile time error : #include <stdio.h> int main(int
#include <stdio.h> #include <stdlib.h> #include <time.h> void initDeck (int deck[]); void showDeck (int deck[]);
#include<stdio.h> #include<time.h> int main() { clock_t start; double d; long int n,i,j; scanf(%ld,&n); n=100000;
Whenever I use the rand function in C++: #include<iostream> #include<time.h> #include<stdlib.h> using namespace std;
Consider this code: #include <iostream> template<class C> struct time { }; int main() {
When I use this #include<time.h> //... int n = time(0); //... I get a
#include <stdio.h> #include <pthread.h> #include <time.h> #include <stdlib.h> typedef struct pr_struct{ int owner; int
The code: #include stdafx.h #include stdio.h #include math.h #include stdlib.h #include time.h int main()
From /usr/include/time.h: /* Used by other time functions. */ struct tm { int tm_sec;.

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.