guys, I am implementing hash function in below code snippet but unfortunetly getting segmentation fault. Could you please help me to understand that what went wrong in this implementation. #include<stdio.h> #include<string.h> #include<stdlib.h> unsigned long hash(char** str ) { unsigned long hash_val = 5381; unsigned long sum=0; char* val ; int i,j; for ( j=0;j<9;j++) { val=malloc(strlen(str[j])+1); memset(val,'\0',strlen(str[j])+1); strcpy(val,str[j]); for (i=0;val[i]!='\0';i++ ) { sum=sum+val[i]; } printf("%ld",sum); return sum; } } int main() { int i; char *str[9]={"mohan","ramesh","mohan","ramesh","cat","act","manish","vashsh","dfjdsj"}; unsigned long key; for(i=0;i<9;i++) { key= hash(str[i]); printf("\nkey[%ld]:val[%s]",key,str[i]); } return 1; }

Member Avatar
Member Avatar
+0 forum 3

Hi everyone I need a suggestion on detecting the faults/bugs in a java program. To say I should check whether my program is faultless. Thanks, Varun Krishna. P

Member Avatar
Member Avatar
+0 forum 7

Hello. I need to set up some pipes for a homework assignment as part of a bigger project. The issue I'm having is that the array (args) I'm using to populate the pipe arguments keeps segfaulting and I don't know why. Everything has been malloced beforehand and the faults only occur at the mentioned places. Below, the relevant code: char** args; char** pipe1_args; int pipe1_args_size; char** pipe2_args; int pipe2_args_size; while (temp_std_command && array_size <= 255) //take args and break them up into an array { args[i] = malloc(sizeof(char)*255); strcpy(args[i], temp_std_command); temp_std_command = strtok(NULL, " "); i++; array_size++; } i++; array_size++; …

Member Avatar
Member Avatar
+0 forum 2

This is more of a tale of "I think I broke it". Basically as an assignment for CS I have to write an assembler for a subset of the MIPS assembly language. Currently it is not working, getting a sigseg, so I decided to debug the code and step through it line by line. Every time I reach line 65 I get these messages from Code::Blocks: At D:\C++\MIPSAssemblerCS241\asm.cc:65 Program received signal SIGSEGV, Segmentation fault. On top of that I get little pop-up windows in the corners warning me about the very same segmentation fault. As such I naturally inspected line …

Member Avatar
Member Avatar
+0 forum 5

Hey I have an code in Qt that is an QPushButton is hidden at start of the cpp but later i want to get it appear when the file is open and an line is readed but the problem i get an segmentation fault. Can be because the setHidden(true) in an another function the problem? Here goes the codes it's worth more than simple words FenPrincipale.cpp #include <iostream> #include <fstream> #include <string> #include <QApplication> #include <QLabel> #include <QComboBox> #include <QMessageBox> #include <QLabel> #include <Qt> #include "FenPrincipale.h" #include "Personnage.h" #include "Ennemis.h" #include "Barbare.h" #include "Magicien.h" #include "LevelUp.h" #include "UtiliserObjet.h" #include "SystemeBataille.h" …

Member Avatar
+0 forum 0

Hi I have a little C-program and when I run I discover alot of page fault?! How can I improve my C program to have it faster?

Member Avatar
Member Avatar
+0 forum 3

I's running this on visual c++ and it runs without error. However, when I tried to run this on Linux, it kept giving me this "segmentation fault" message without any output. There is no pointer and is a quite simple program so can anyone please tell me what is wrong?? here's the program! #include <iostream> #include <string> #include <cassert> using namespace std; int positionOfMax(const string a[], int n) { if (n <= 0) return -1; if (myStrlen(a) == 0) return -1; string max = ""; int i = 0; int keep; while (i < n) { if (max < a[i]) …

Member Avatar
Member Avatar
+0 forum 5

Im having some trouble putting together a linked list implementation of a queue. I'm getting a segmentation fault, which I believe is due to my empty() function because in an attempt to fix my empty() function, I made it determine empty based on (current_size == 0) instead of (front_p == NULL). Based on the test program that I ran enqueue, dequeue, etc all work properly. Even empty() works to check if the queue is empty() at the beginning of the program. But after dequeueing everything, the final check for empty() fails; hence why I decided to make the above changes …

Member Avatar
Member Avatar
+0 forum 1

Hello, I am writing a program that reads in data from a text file and puts it into a linked list. Certain variables are read in only if the "officeHeld" number is a particular number, otherwise the variable is set to 0. When I run this through Visual Studio, I get a blank black screen with nothing on it. When I run it through our university's unix, I get "segmentation fault". I am not sure where the error is here and I'm at a loss. Any help or suggestion would be overwhelmingly appreciated. I'm attaching the code as well as …

Member Avatar
Member Avatar
+0 forum 4

Hi can someone point me to a C# project for a tracking system. which is implemnted in C#. my question is it has 2 processors and four track manager system can someone give me an tutorial to get started. appreciate it thanks

Member Avatar
+0 forum 0

Hi, I'm new to C++. plzz help me with this error. #include <cstdlib> #include <iostream> #define clauselength 85 //we will use index number to find out the clause number. //there are 88 clauses. as we start using index from 1 we have to add one to 89. using namespace std; string clause_variable_list[clauselength]= { "","ATTACK_FOUND","","","", "IP_SPOOFING_ATTACK","","","", "IS_SPOOFING_REFERS","","","", "IS_CALLER_ID_ATTACKS","","","", "IS_EMAIL_ADDRESS_REDIRECTING","","","", "SNIFFING_ATTACK","","","", "MATCH_IDENTIFICATION","","","", "ENCRYPT_EMAILS","","","", "MALWARE_ATTACK","","","", "IS_ANTIVIRUS_RUNNING","","","", "INSTALL_VIRUS_SCANNER","","","", "IS_ID_ON","","","", "TROJAN_ATTACK","","","", "IS_ATTACK_MALLICIOUS","","","", "IS_SYSTEM_PERFORMANCE_SLOW","","","", "IS_IT_DOS_ATTACK","","","", "IS_IT_PING_FLOOD","","","", "IS_IT_PING_DEATH","","","", "IS_SMURFING","","","", "IS_FRAGGLE","","","", "IS_IT_SYN_FLOOD","","","" }; int getClauseNumber(string str, int afterindex=0) { for(int i=afterindex+1; i<=84; i++) { if(str==clause_variable_list[i]) { return i; } } return -999; } class variable_list { string name; …

Member Avatar
Member Avatar
+0 forum 3

Here I have the classes Logger and Driver. Driver takes the singleton class of Logger, and logs the same statement 10000 times. I want to use this logger, so that it runs in the background and only logs every so often. This will force the program to not use too much cpu time to log data, but rather other crucial tasks. #pragma once #include <deque> #include <string> #include <fstream> #include <map> #include <iostream> #include <pthread.h> #include <time.h> #define MAX_LINES 10000 #define MESSAGES_PER_WRITE 101 namespace App { class Logger { friend class Driver; friend class OrderManager; public: static Logger* Instance(); void …

Member Avatar
Member Avatar
+0 forum 5

plz help me to solve the error in this program : Given programs replaces multiple spaces with only one space... there is no error , but it shows "Segmentation Fault"...whats the issue ????????? #include<stdio.h> int main(void) { char *t="ALOK KUMAR ASHISH KUMAR ANKUSH"; char *c; int n1=0; while (*t) { if (*t==' ') n1++; if(n1>1) { *t=*(t-1); n1--; } *c=*t; t++; c++; } printf("%s",t); return 0; }

Member Avatar
Member Avatar
+0 forum 1

#include <stdio.h> #include <stdlib.h> long i,j,k,*ni,qi,a,*arr,n,q,p,no,c=0,m,max=0; int main() { ni = malloc(sizeof(long) * 100000); arr=malloc(sizeof(long)*10000); scanf("%ld",&no); for(i=1;i<=no;i++) { scanf("%ld %ld",&n,&qi); for(j=1;j<=n;j++) { scanf("%ld",&ni[j]); } for(k=1;k<=qi;k++) { scanf("%ld %ld %ld",&a,&p,&q); while(p<=q) { arr[++c]=ni[p++]^a; } for(m=1;m<=c;m++) { if(arr[m]>max) { max=arr[m]; } } printf("\n%ld",max); max=0; c=0; } } return 0; } Bold Text Here

Member Avatar
Member Avatar
-1 forum 8

Hi, I'm writing a small C program to clean the radius radacct table, removing ended sessions records and inserting on a separated database. The problem is that MySQL C API doesn't have an easy way to insert the result of a query on another database/table directly, you have to build a custom insert statement, I'm trying to do that, I'm using strncpy to copy the fields on the result row to the insert statement char array. It works for just a few records, than it returns me a segmentation fault error, here is the piece of code where the copy …

Member Avatar
Member Avatar
+0 forum 4

Hello all! I have used this forum many times in the past to solve a variety of programming related problems, but am truly stumped on a segfault within a binary search tree. I have isolated the segfault to a fscanf statement that look legitamate to me. The following code blocks are the function that contains the fscanf statement: int fscan_unit(FILE *filep, object_t *object){ int status; /************************** SEGFAULT **************************/ status = fscanf(filep, "%d%d%d%s", &object->id, &object->section, &object->credits, object->course ); /************************** SEGFAULT **************************/ if(status == 4){ status = 1; } else if(status != EOF){ status = 0; } return status; } and the …

Member Avatar
Member Avatar
+0 forum 2

Hi all !! I am new to Fortran. Please see the following code: program exp_realloc implicit none integer,allocatable,dimension(:,:):: array integer::i,j allocate(array(3,3)) write(*,*)size(array,1)," ",size(array,2) do i=1,3 do j=1,3 array(i,j)=i*j write(*,*)array(i,j) enddo write(*,*) enddo CALL func(array) end program exp_realloc subroutine func(array) integer,dimension(:,:),intent(in)::array integer::i,j write(*,*)"********* Inside subroutine **********" write(*,*)size(array,1)," ",size(array,2) write(*,*)array(1,1) write(*,*)array(1,2) write(*,*)array(2,1) do i=1,3 do j=1,3 write(*,*)array(i,j) enddo enddo end subroutine func The output is: 3 3 1 2 3 2 4 6 3 6 9 ********* Inside subroutine ********** 131097 1 Segmentation fault Two questions: 1. Why is the size of array not being printed correctly in the subroutine? 2. Why …

Member Avatar
+0 forum 0

main.c #include <stdio.h> #include <stdlib.h> #define MAX_USERS 100 typedef struct Utilizadores{ char *login; char *pwd; } USERS; void ReadUsers(USERS user[]); int u = 0; int main(){ USERS user[MAX_USERS]; ReadUsers(user); return 0; } void ReadUsers(USERS user[]){ FILE *fp; fp = fopen("/home/Jiwe/Desktop/users.txt", "r"); while(fscanf(fp, "%s[^=]=%s\n", user[u].login, user[u].pwd) != EOF){ u++; } fclose(fp); } Hey guys, I get a segmentation fault error using the code above. For now I just want to read the login name and password of a user from a text file, so later I can show it. The text file is filled like this: LOGIN=PASS LOGIN2=PASS2 ... etc I …

Member Avatar
Member Avatar
+0 forum 5

I was wandering what could be the causes of this error message? Like in general. `\\: *stopped,reason="signal-received",signal-name="SIGSEGV",signal-meaning="Segmentation fault",frame={addr="0x00402d53",func="Domain::Movie::show",args=[{name="this",value="0x1"}],file="..\\src\\Domain\\Movie.cpp",fullname="e:\\eclipse for c++\\workspace\\lb6-8oop\\src\\domain\\Movie.cpp",line="36"},thread-id="1",stopped-threads="all"` 10x.

Member Avatar
Member Avatar
+0 forum 7

#include<stdio.h> int strlen_(const char *string); int strlen_(const char *string) { int length; for(length = 0; *string != '\0'; string++){ length++; } return length; } char *strcat_(char *string1, const char *string2); char *strcat_(char *string1, const char *string2) { char *p = string1; if(string1 == NULL || string2 == NULL) return string1; while(*string1 != '\0') string1++; while(*string1++ = *string2++) ; return p; } int main() { char *string1 = "my"; char *string2 = "me"; int num = strlen_(string1); printf("the length before strcat is %d\n", num); strcat_(string1,string2); int num2 = strlen_(string2); printf("the length after strcat is %d", num2); printf("\nThis is it!\n"); return 0; …

Member Avatar
Member Avatar
+0 forum 1

hi all, total noob here with assembly. I'm working on a project for one my classes and for some reason we all keep getting segmentation faults when attempting to run the program. I can't for the life of me figure out what the heck is going on and why this keep happening. I have tried to go though the program and remove things little by little to see if I could find the cancerous lines but I was unable.. As a last resort I've come to Daniweb to see if anyone can spot it for me... (My instructor was not …

Member Avatar
Member Avatar
+0 forum 1

[code]for(int i=0;i<=c;i++) { l=0; if(strcmp(findedge(tst[i],dfa[0][j]),"null")!=0) { strcpy(t1,findedge(tst[i],dfa[0][j])); //l=strlen(temp); strcat(temp,","); strcat(temp,t1); //temp[l+1]='\0'; //temp[l]=','; } } [/code] When I try to append comma or some other symbol to temp, a segmentation fault occurs. If that step is omitted everything works perfectly. This is code is from my program to convert NFA to DFA. You can see that I even tried to manually append the comma without using strcat from those commented lines. Somebody please help me

Member Avatar
Member Avatar
+0 forum 11

Here are program instructions. IT SAYS "segmentation fault" WHEN RAN. Specifications You must create a Ship class: The Ship class maintains the position data for each ship/vessel and its distance from another Ship. It has a default constructor, which sets all of the member data to zero, and a non-default constructor that has three parameters, one for each coordinate. It contains methods to calculate the distance to another Ship and to retrieve that distance later. You must also overload a relational operator, such as < or >, for use in a sorting routine. Thus, a Ship object can report whether …

Member Avatar
Member Avatar
+0 forum 2

Hi this my first post here XD Its like this i have the code writen but it gives me this error Segmentation fault (core dumped) Can anyone tell me why? [code] MAX_BUFFER equ 10240 ; Constante que sera' usada como tamanho maximo de cada linha lida do teclado (10kb) FICH_ABERTURA equ 00q ; Constante que sera' usada como tipo de abertura pretendido: O_WRONLY + O_CREAT ;----------------------------------------------------------------------------- section .data fich_nome db "teste.txt", 0 ; Nome do ficheiro a abrir (em formato ASCIIZ) fich_handle dd 0 ; Variavel que vai guardar o numero (handle) do ficheiro fich_bytes dd 0 ; Variavel que …

Member Avatar
Member Avatar
+0 forum 1

I have a simple doubly linked list for a class I am in and I keep getting a seg fault on my last line of code, no matter what i make it. I can put a bunch of random couts and it will print them all then on the last one seg fault, all my test functions are working how they should too. Any idea what would cause a seg fault? only things in the class are what my prof says are the typical functions... The big 3, popBack/front, pushback/front and a few others that already work as they should... …

Member Avatar
Member Avatar
+0 forum 6

I wrote this program and it compiled with no errors or warnings but when i went to run it i get a segmentation fault and i cant figure out what is causing it. Ive spent hours and hours on this . Anyone with some expertise willing to take a look? [CODE]#include <stdio.h> #include "my.h" int main(int argc, char* argv[]) { int **a; int rows, cols,j,k; FILE* p; int i; fopen(argv[1], "r"); fscanf( p, "%d", &rows); fscanf( p, "%d", &cols); printf("works here"); a = (int**)calloc (rows, sizeof(int*)); for (i = 0; i <rows; i++) { a[i] = (int*)calloc (cols, sizeof(int)); } …

Member Avatar
Member Avatar
+0 forum 2

I am currently creating a queue ADT for one of my classes in college. We are using a linux ssh server for compiling our programs, but i am writing the code in windows. When i compile i get no errors, but when i run it goes fine until it hits the copy constructor Queue300 two(one); at which point i get a segfault and the program ends. im sorry if its a little cryptic to read but my instructor believes that typedef is the most amazing thing since sliced bread. my code is as follows: [B][U]header[/U][/B] [CODE]#ifndef OBERLOHA3_H #define OBERLOHA3_H typedef …

Member Avatar
+0 forum 0

Please help me find the error with my code. Whenever I try to run the program, it returns a Segmentation Fault message. I've been trying to find and play with the codes but I'm really stuck.. Please help me.. Here's my code: [CODE] .section .data format: .asciz "%d\n" values: .int 5, 3, 2, 4, 7 smallest: .int 0 .section .text .global _start _start: leal values(, %edi,4), %esi movl $4, %ecx #outer loop counter movl $4, %ebx #inner loop counter movl (%esi), %eax movl %eax, smallest addl $4, %esi dec %ebx jz output loop: movl (%esi), %eax cmp smallest, %eax jl …

Member Avatar
Member Avatar
+0 forum 1

Hello all, I was trying this problem of checking if the input integers can be ordered using the STL implementation of the stack. The program reads from a file named "input.txt" which in its first line has the number of integers that follow in the second line. The second line integers are the ones that are to be ordered. My code: [CODE]#include<iostream> #include<cstdlib> #include<stack> #include<fstream> using namespace std; int main() { stack<int> st; int no,temp,last=1,x; bool startfound=false,possible=true; ifstream in("input.txt"); if(!in) { cout<<"No such file"<<endl; exit(EXIT_SUCCESS); } in>>no; while(no){ last=1; startfound=false; possible=true; while(!startfound){ in>>temp; cout<<temp<<" "<<startfound; if(temp==1) { startfound=true; } else{ …

Member Avatar
+0 forum 0

Just took my old desktop out of storage... Its from 05/06 ish... and 2gb of its RAM is faulty :( - Wont boot with it in. Any ideas why this is? The slots themselves don't seem to be faulty, just the sticks....

Member Avatar
Member Avatar
+0 forum 18

The End.