C/C++ :: Segmentation Fault With GDB Result Change Information From Binary File
Jan 4, 2015
I'm trying to change some information from binary file but I get segmentation fault. Suppose there are two teams which names are same. The names are wanted to change. But, I get segmentation fault.
team_name, city , stadium ,fdate, colors
the team is in binary file
manunited,manchester,old_trafford,1878,black-rd
chelsea,london,stamford_bridge,1905,blue-whte
manunited,manchester,old_trafford,1878,black-rd
[Code] ....
View 4 Replies
ADVERTISEMENT
Feb 25, 2015
A part of the problem I am trying to solve includes constructing a binary search tree from a sorted array. When ever I try to implement the same, it results in a segmentation fault.
Code:
#include <stdio.h>#include <malloc.h>
#include <stdlib.h>
struct BSTNode{
unsigned long long int data;
BSTNode* left;
BSTNode* right;
[Code]...
The Seg fault happens in the function sortedArrayToBST().
Please ignore any unused variables as they are for future use.
View 1 Replies
View Related
Mar 21, 2014
I'm writing a binary search tree program and I got it to compile but as soon as I input something it returns a "segmentation fault error" . I suspect the issue with the code is withing my `add` function.
template<typename T>
void BinarySearchTree<T>::add(T value) {
if (m_root == nullptr) {
Node<T>* node = new Node<T>;
node->setValue(value);
m_root = node;
[Code] ....
View 6 Replies
View Related
Apr 26, 2013
I have written a small program for a class to convert decimal to binary and the program itself works, however, I am storing the binary bits in a stack that is in a header file (which I have used successfully before). It appears to push the bits to the stack just fine, however, when I use the printStack function I get a segmentation fault.
Here is the stack.h header file:
Code:
#include <stdlib.h>
#include <stdio.h>
struct stackNode {
int data;
struct stackNode *nextPtr;
[Code].....
And here is the main program that does the conversion:
Code:
#include <stdio.h>
#include "stack.h"
int binary (int x);
int main() {
int choice = 0;
printf("
[Code].....
One other thing of note, whenever I try to modify the printStack function, that function then seems to not work at all.
View 12 Replies
View Related
Sep 28, 2013
question regarding some segmentation fault I receive while running the code I have been working on. I am working on a card program and this is my input:
Code:
TS QC 8S 8D QH 2D 3H KH 9H 2H TH KS KC
9D JH 7H JD 2S QS TD 2C 4H 5H AD 4D 5D
6D 4S 9S 5S 7S JS 8H 3D 8C 3S 4C 6S 9C
AS 7C AH 6H KD JC 7D AC 5C TC QD 6C 3C
3C 6C QD TC 5C AC 7D JC KD 6H AH 7C AS
9C 6S 4C 3S 8C 3D 8H JS 7S 5S 9S 4S 6D
5D 4D AD 5H 4H 2C TD QS 2S JD 7H JH 9D
KC KS TH 2H 9H KH 3H 2D QH 8D 8S QC TS
What I am trying to do is read in 52 cards name into array, set up the game and play it, when the game is done, I read the next 52 cards and play it again.
However, I encounter segmentation fault while running the program. Here is my code
Code:
#include <stdio.h>#include <stdlib.h>
#include "header.h"
extern FILE *open_file();
[Code].....
View 3 Replies
View Related
Oct 28, 2014
Below is my sample code of a C program. I am doing lot of processing, but my issue is I am getting a segmentation fault error in my main when I am putting the file names at the command line and using them. The program works great in Windows, but its giving error in Unix.
Below is the code of my Main function.
Code:
int main(int argc, char *argv[])
{
FILE *user, *requests;
char c;
user = fopen(argv[1], "r");
requests = fopen(argv[2], "r");
//For users
struct userStorage *USHead = NULL;
//struct users *userHead = NULL;
[Code]...
View 6 Replies
View Related
Oct 21, 2013
I have to txt files, and want them to read into an array line by line and after then a split the lines with delimeters, at the first file I use ";", at the second file I want to split the lines to single words by spaces. My aim is to get the first word from the first file and compare with all the words from the other file, to check is there any matches.
My problem is, that at the first file works everything fine, and I want to do the with the second file, but after reading the lines into lines_input[], I check the an empty = null line, I get segmentation fault.
You can see the code below:
Code:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
//Change the
[Code] .....
View 1 Replies
View Related
Jan 21, 2015
I try to crypt file with XOR instruction, by always receive segmentation fault. What's wrong with it?
Code:
#include <stdio.h>
main() {
FILE *fin,*fout;
char buff[40];
int a=0x11;
int i=0;
[Code] ....
View 4 Replies
View Related
Jan 3, 2015
I am working on binary files in turbo c++ 3.5 and i want to create a library program. I want to add information about books in a binary file and do functions such as: Search and replace, delete a record, and etc.
I do this functions but i have 2 problems: 1. For example when i add 6 records about books to file, BooksReport function cant show all records and for example just show 4 or 5 records and when i search records, from 5 records, for example i just found 3 or 2 records. 2.When i search and replace a word on file, all records thats before this edited record, will be deleted.
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void add();
void search();
struct {
char name[20];
[Code]...
View 2 Replies
View Related
Jan 23, 2013
I am working on a distributed application in C. My program gives segmentation fault and aborts execution. But, when I try to run it through gdb, it keeps on running although without giving a useful output. I realize that I do not put much information in my query. But, what general causes could generate this behaviour. I am interested to find the cause of segmentation fault.
View 8 Replies
View Related
Jul 21, 2013
I can't understand why my program keeps on getting "Segmentation Fault". The last time I checked (in UBUNTU) it was already working, now I'm testing it in Windows and I keep on getting "Segmentation Fault".
Code:
#include <stdio.h>
#include <string.h>
int main(){
char string[1500];
char word[100];
}
[code]....
View 10 Replies
View Related
Oct 28, 2013
Writing a program to search a file and print out the occurrences of each letter in the alphabet.
Code:
#include <stdio.h>
char input[500];
int input_c[26];
int i;
char count=0;
}
[code]....
View 8 Replies
View Related
Jan 16, 2015
I am using scientific linux. In the directory user/project/Build, after I ran 'make' to compile and link all the cpp files,I had no problems. But then, when I went to directory user/run/run.sh, which runs the project binary in user/project/Build/bin/project, I get a segmentation fault error. In the directory user/run, I enter 'gdb' in the command prompt and get the message "*** No targets specified and no makefile found. Stop." What am I supposed to do to detect the segmentation fault?
View 2 Replies
View Related
Jun 28, 2013
I can't work out why I get a Segmentation Fault with my C++ program.
Here is the code:
#include <iostream>
#include <string>
#include <stdexcept>
[Code].....
View 5 Replies
View Related
Dec 7, 2014
GameMaster.h
#includes ...
class GameMaster
{
[Code].....
I get the segmentation fault whenever it tries to insert the first player.. however whenever i do this :
void MakeSquad(char type, string name, int coordX, int coordY, char dir, int squad)
{
GameSpace::MapSquadType MapOfSquads;
MapOfSquads.insert(make_pair(name , Squad(squad)); // Squad( int ) just converts the int squad number to the Enum.
}
I do not get any errors or segmentation faults..
View 5 Replies
View Related
Feb 25, 2012
Code:
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define FILEPATH "./input.txt"
#define FILEPATH2 "./copy.txt"
[Code] ....
The problem is probably the fact that I'm using the variable s in the wrong way, but as I'm very bad at C and C++, at least so far anyway, I've no clue what's wrong. Is it my size that I passed in the marked method?
Also, how do I tell it, later, once this starts to work, to pass the file name of the file it'll copy to as the first param and the file it reads from to the pipe as the second param?
I'm supposed to be reading from a file, and as I was given some code, but it's probably in C and not C++, even if it is, I'm still not that great at C++ either, but anyway, I'm to have the program read from the file and write to the pipe and have the child read from the pipe and write to the output file.
FileCopy copy.txt input.txt
View 14 Replies
View Related
Apr 7, 2013
Is it possible to prompt information from user then display the result in a one dimensional array form? If yes, how should i link them together?
View 7 Replies
View Related
May 3, 2013
The point of this code is to get 15 names and then hash them. After one name is entered I get a segmentation Fault and the program crashes.
Code:
//driver file
#include <iostream>
#include <vector>
#include <string>
using namespace std;
[Code] ....
View 7 Replies
View Related
May 29, 2013
I have this piece of code that causes segmentation fault:
Code: .... check argv[2] exists ....
std::string* op_file;
...
std::cout << "argv[2] is: " << argv[2] << std::endl;
op_file = new std::string(argv[2]);
...
The result I am getting is:
Code: argv[2] is: somefile.txt
Segmentation fault (core dumped)
View 3 Replies
View Related
Jul 7, 2014
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
/* h(a)=abcab,h(b)=acabcb,h(c)=acbcacb */
void h_i(int i, char *w, char *a, char *b, char *c)
[Code] .....
Above program increases string like this example.
Let say h(0)=01 and h(1)=10 and let say our first string is w=0 h(w)=01, h^2(w)=0110 h^3(w)=01101001..etc.
We have used h map, which is given in the program comment statement. Same thing, program is doing for three letters. These three letters we have passed as argument in h_i function. e.g. h_i(2,w,"a","d","g") function will apply the 3 letter map h(definition is given in commented form in program) 2 times on string w.
In program w=a; and three letters are a, d and g. /* h(a)=abcab,h(b)=acabcb,h(c)=acbcacb */ here b=d and c=g.
Above program gives core dump at free(w2) free(w1). if we remove these free statements then it gives correct answer. But, we want to free w1 and w2 in the above code. How can we make free both w1 and w2 strings?
View 4 Replies
View Related
Apr 15, 2013
I want to know what was wrong with my code when I submitted. It's a Traveling Salesperson Problem, and the code is complete for the most part. I just can't seem to find what's causing the segmentation fault even after attempting to debug with gdb. Something is supposed to be wrong with line 76, but I don't see how my arrays are messing up. I've looked through this code countless times, and I know I'm just missing something small. I just don't want to end up making whatever mistake I made on this again in the future.
Code:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 20
[Code]....
View 9 Replies
View Related
Feb 18, 2013
I am having trouble running the following code. I am getting a message segmentation fault (core dumped)
Code:
#include<stdio.h>
#include<ctype.h>
#include<time.h>
main() {
int iuser;
int irand;
srand(time(NULL));
[Code] .....
View 2 Replies
View Related
Nov 6, 2013
Despite seeing the correct data in gdb when I
Code:
p *(DownloadFileChunkResponse.DownloadFileChunkResult)->__ptr@100
The following C code gives me a SEG FAULT
Code:
calloc(NewMediaChunk, ChunkSize);
memcpy((void *)NewMediaChunk,
*(DownloadFileChunkResponse.DownloadFileChunkResult)->__ptr, ChunkSize);
How I got this wrong. BTW The data I am attempting to memcpy is the frontend of an MP4 file containing a number of NULLS.
Code: 00 00 00 30ftypmp42 00 00 00 00mp42mp41 00 00 dfree
BTW ChunkSize is 64000
View 9 Replies
View Related
Apr 11, 2013
On compilation the following program does not give any error and when i run this program then sometimes it gives the segmentation fault. Specially with the larger values. I made sure that the values i inputted are not crossing any range of data types i used. I cannot get what is making my code to give segmentation fault error.
Code:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
[Code] ....
View 4 Replies
View Related
May 30, 2014
I have a problem in my code and after hours of looking I really cannot find out what is the problem.I use scanf to to parse lines of a file, let me copy only the important part:
Code:
/*File read...everything is fine*/
int seq_1, seq_i2;
int len;
while(fgets(&line[strlen(line)], line_length, file)!= NULL) {
}
[code]....
if (num_sc ==4) //the wanted format, do something So I am allocating all variables, and giving to sscanf pointers, so I really don't get where the segmentation fault appears.I checked with the debugger, the first line of the file is read, but at the second it crashes at the line of sscanf! The two lines don't have the format I want in sscanf but therefore I check if this number is 4 and then do other stuff to the data...
View 9 Replies
View Related
Apr 11, 2013
It is suppose to display the message "This Account ID does not exist" but why do I get "segmentation fault"??I was able to compile and run the program so it shouldn't be a problem of the compiler.
Code:
#include <stdio.h>#include <string.h>
struct Account {
char* Account_ID;
char* Account_Type;
char* AccountOwner_FirstName;
char* AccountOwner_LastName;
float* Balance;
[Code]....
View 11 Replies
View Related