473,480 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

segfault

1 New Member
i dont know what should i do whit this segmentation fault.....plz help me!!!

Expand|Select|Wrap|Line Numbers
  1. #include <cstdlib>
  2. #include <ctime>
  3. #include<iostream>
  4. #include<fstream>
  5. using namespace std;
  6. int random(bool[][1000],int , int);
  7. int main()
  8. {
  9.     int n;
  10.     int counter=2;
  11.     cout<<"enter your number"<<endl;
  12.     //getline(cin , n);
  13.     bool array [1000][1000];
  14.     cin >> n;
  15.     for(int i=0; i<1000; i++){
  16.         for(int p=0; p<1000; p++){
  17.             array[i][p]=false;
  18.             //cout<<"ss";
  19.         }
  20.     }
  21.     cout << "inadlkv";
  22.     cout<<"chand ta jaygasht(bishtar az n! nabayd bashe!!!)";
  23.     for(int k=0; k<counter; k++){
  24.         cout<< "jaygashte  ";
  25.         for(int i=0; i<n; i++){
  26.             cout<<random(array , n, i)<<"   ";
  27.         }
  28.     }
  29.             return 0;
  30. }
  31. int random(bool array[][1000] , int n , int i) {
  32.     srand(time(NULL));
  33.     int a=rand() % 1000 ;
  34.     for(int j=0; j<n ; j++){
  35.         if( (!array[i][j])&&(j==a) ){
  36.             array[i][j]=true;
  37.             return(a);
  38.         }
  39.         else
  40.             return(random (array , n , i));
  41.     }
  42. }
Mar 10 '12 #1
1 1707
weaknessforcats
9,208 Recognized Expert Moderator Expert
You are accessing memory that does not belong to your variable. You have to fix it. Most likely this is an access outside an array due ti an error in your code or to using C-strings. Be sure all your buffers are large enough. You may have to step through the code using your debugger.
Mar 10 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
3132
by: Nathaniel Echols | last post by:
I've written a function in C to perform protein sequence alignment. This works fine in a standalone C program. I've added the necessary packaging to use it in Python; it returns three strings and...
6
2998
by: Juho Saarikko | last post by:
The program attached to this message makes the Python interpreter segfault randomly. I have tried both Python 2.2 which came with Debian Stable, and self-compiled Python 2.3.3 (newest I could find...
6
1964
by: Stefan Behnel | last post by:
Hi! In Python 2.4b3, the deque is causing a segfault on two different machines I tested on. With deque, my program runs fine for a while (at least some tens of seconds up to minutes) and then...
0
1809
by: dale | last post by:
Python newbie disclaimer on I am running an app with Tkinter screen in one thread and command-line input in another thread using raw_input(). First question - is this legal, should it run...
10
2875
by: Arthur J. O'Dwyer | last post by:
I'm seeing a bug at the moment that I can't track down. It's part of a moderately large program, but here is a small program that exhibits the bug on gcc. (The program code follows at the bottom...
4
1868
by: Jim Strathmeyer | last post by:
Under what circumstances would closing a istream object (such as 'in.close()') SEGFAULT?
4
3482
by: William Payne | last post by:
Hello, I was under the impression that if I made a class Foo and if I didn't specify a copy constructor I would get one anyway that simply assigns the member variables (and that won't work for...
10
1917
by: name | last post by:
When I started testing the algorithms for my wrap program, I threw together this snippet of code, which works quite well. Except that it (predictably) segfaults at the end when it tries to go...
3
2287
by: kj | last post by:
I am trying to diagnose a bug in my code, but I can't understand what's going on. I've narrowed things down to this: I have a function, say foo, whose signature looks something like: int foo(...
14
4934
by: Donn Ingle | last post by:
Yo, An app of mine relies on PIL. When PIL hits a certain problem font (for unknown reasons as of now) it tends to segfault and no amount of try/except will keep my wxPython app alive. My first...
0
6918
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6756
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4495
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3008
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3000
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1310
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.