C :: Getting Seg Fault At Read Function
Oct 17, 2013
I have a c source file:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <regex.h>
typedef struct
[Code] .....
But the problem is i get a seg fault at the read function.
View 2 Replies
ADVERTISEMENT
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
Mar 12, 2015
#include<stdio.h>
#include<stdlib.h>
#include<sys/time.h>
#include<time.h>
#include<math.h>
typedefstruct points{
float axis[2];
[Code] .....
View 6 Replies
View Related
Apr 12, 2014
Task: To create a recursive function to sort elements in an array of integers.
The function must start the sorting from the first element, and the recursion calls must go on until the last element in the array is sorted. In each step of recursion, the function must work only with the subset of array elements that have not been sorted yet.
Problem: I am getting a 'Segmentation fault: 11' in the recursive call to the function (please, see the code below).
Environment: Mac, OS X = Mavericks
Code:
////////////////////////////////////////////////////////////////////////////////
////////// Recursively sorting an array of ints.
////////// Arguments: array, array size, index from where to start sorting.
void sort_incr_array_int_recursive(int a[], int size, int i){
int tmp, idx_small, small = a[i];
// Locating the smaller element in the array section.
[Code] ....
View 4 Replies
View Related
Sep 21, 2014
I`ve almost finished the program I am working at ( not commercial, it`s for me ). And I still can`t get what is wrong. I get segmentation fault on 2nd call of specific function. I have 2 lists of strings. One for directories, one for files. A function to walk a directory recursively, and to add to front in both lists respectively for files and for dirs. Then do something on these files. Here is my code for the functions I am using and will explain where I am failing.
DList.cpp Code: DList* createList(const char* message) {
DList* dl = (DList*)malloc(sizeof(DList));
dl->head = dl->tail = NULL;
printf("List created at %p; message:[%s]
", dl, message);
if ( dl != NULL ) return dl;
else return NULL;
[code]....
What fails? Well after the first press of p/P, it lists and prints the dir/filse. On second press it gives me a segphault. Really no idea what I got messed up. I`ve listed all the functions I am using ....
View 6 Replies
View Related
Mar 24, 2014
It is been several days that I am stucked with the segmentation error and I do not know anymore what to do I try to do a loop over my function but it is working only for my first iteration. Here the code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
[Code].....
I would like to iterate over solvep (since h is changing at each iteration..I usually add other fct but now I try to debug why the loop is not working.).The first iteration is working fine but not the other iterations.
View 4 Replies
View Related
Dec 8, 2013
Is possible read text form keyboard using read() function? or which is best way in ansi creplace input command form basic language. for numbers and text...
View 3 Replies
View Related
Oct 9, 2013
Write a function that sorts a dictionary list alphabetically. Here's my code:
Code:
#include <stdio.h>
#include <stdbool.h>
struct entry
{
char word[15];
char definition[50];
[Code] ....
It's compiling ok, and displays the first call to the printf function from main. However, after this I get the 'Segmentation fault (core dumped)' at the terminal, presumably from the call to the dictionarySort function.
I had a little look around and found it is something to do with non-existent or not available memory addressing, I think? Even so, I can't figure out what is causing the issue in my code.
View 8 Replies
View Related
Apr 20, 2014
is there a function or something that take HEX and print it's corresponding ASCII Character ..
Here is my Code to take Character Array [4] and Print it's HEX to File ..
but i don't know how to reverse ! ?
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main(){
char buffer[4];
[Code] .....
View 1 Replies
View Related
Nov 2, 2014
ok so I have three numbers in a file that I called in a function and I want to use all three numbers from that file in another function how can I??
View 9 Replies
View Related
Apr 16, 2015
I am currently in a beginner C programming class. I have written most of my code and the problem that I am running into when i compile and run the code. I am able to input more than required scores for input. I think my code is wrong from line 126-136. The program runs fine with no errors. I'm just unable to input the required number of scores allowed.
/*************************************************************************
* A program to calculate grade.
*************************************************************************/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
[Code].....
View 2 Replies
View Related
Sep 27, 2014
called object 'fptr_in' is not a function or function pointer
called object 'fptr_out' is not a function or function pointer
what can i do for the errors?(i mustn't use loop and arrays for the code)
Code:
#include <stdio.h>
void sum_of_2nd_and_3nd( FILE* fptr_in, FILE* fptr_out);
int main()
return 0;
}
void sum_of_2nd_and_3nd( FILE* fptr_in, FILE* fptr_out){
}
[code].....
View 2 Replies
View Related
Mar 1, 2013
I am developing a program that will read a function (x^2+2x+4 or other function) and then comparing and start assigning variables. My idea is with an array:
int i,x;
char xs;
char function[20];
cin.getline(function, 20);
cout << "Your function is: ";
[Code] .....
Well this is my basically idea, but when the program detect an ^ this will be associate with the exp(x,n); well in general the user enter a function: x^3+3x^2+4x-8 give a value for x for example 3 and the program will convert in -- exp(3,3)+3*exp(3,2)+4*3-8 --, but I don't know how.
View 2 Replies
View Related
Mar 17, 2014
code:
/part of main function
int *A=NULL;
//load from file
load_from_file(A, &next);
printf("next=%d
",next);
getchar();
printf("A[%d]=%d
",0,A[0]);getchar();//here program crashes
}
[code]....
I initialize array A with NULL in main, and I "load" it with elements from a file. The code without function is working. But when I tried to use a function as above, my array crashes!!!
View 4 Replies
View Related
Mar 30, 2014
I am writing a program which compresses files into .zip files.
Here's my problem: Whenever I want to compress an executable file, my readFile function does not read the entire file. When I extract the .exe I get a very tiny and incomplete file.
Here's the function I use to read files:
std::string miniz_wrapper::readFile(FILE* f, int MAX_FILEBUFFER)
//MAX_FILEBUFFER has a default value of 65536 {
char* tmp;
std::string tmp_s;
int count = 0;
[Code] .....
Prior to reading, every file is opened using fopen with the mode "rb".
View 6 Replies
View Related
May 27, 2013
I am trying to use fgets to read in a string, but keep getting a "no conversion function from std::string to char" error.
View 2 Replies
View Related
Nov 3, 2014
So for a project, my professor sent out two pages of code containing functions to read a text file (since we do not know how to write this on our own yet). I've got the code working on Orwell IDE and it gives me 2 warnings saying
"Passing argument 1 of 'readFromFile' from incompatible pointer type"
"Passing argument 2 of 'option2Print' makes integer from pointer without a cast"
The Orwell IDE seems to just bypass these warnings and compiles the code correctly. However, when I transferred my files over to my desktop using BloodShed (what the professor uses), instead of getting a warning I get an error and the code won't compile.
I assume it will not compile on his computer either since he uses the BloodShed IDE.
I don't know how to put the code directly into the text neatly, so a attached a .zip file with my code. The "storms.txt" file is also included. (the file that will be read).
View 4 Replies
View Related
Oct 29, 2014
I try to use passing function as argument but I'm stuck. I have two questions: First, I try to call uppercase and open .txt in tfm Second, How can I read characters from in.txt as string and assign to char content[] ?
#include <stdio.h>
void tfm( char str_filename[], void(*pf_convertion)( char content[]));
void uppercase(char content[]); //converts all letters to uppercase
int main(){
puts("-------------------------------");
printf("tfm:
");
tfm("in.txt", uppercase);
[Code] ....
View 2 Replies
View Related
Sep 6, 2013
I am writing an MFC app in Visual Studio 2012 that will open a JPG file as binary and read all the contents to a CString.
I am able to read it to a std::Vector, but that doesn't work much as i need to pass all the binary content as a MFC CString to another function.
More Update:
Let me explain the problem a little more deeper.
I am trying to call a JavaScript (JS) function in a HTML page and then want to pass the binary date. The C++ function that calls the JS is given below.
bool CallJavaScript(const CString strFunc,CComVariant* pVarResult);
The 1st argument is the JS Function Name and 2nd is the one to pass the Binary Data. 1st argument works fine as i am able to call the JS fucntion called "LoadImage" without any problem. Problem is with 2nd argument that's supposed to take the Binary data of the JPG file.
If i try to pass a std::Vector or std::string then it will give me an error.
But it's happy if i pass CString. But then with CString there's a problem with NULL characters.
Actually my plan is to pass the binary of a JPG to a JS function and let it display the JPG in the HTML page.
Can i typecast a Vector or std::string to a CComVariant*?
View 3 Replies
View Related
Mar 25, 2014
identify the reason why I am getting a seg fault run error? I hate to bother but I've been trying for several days now to fix the same function.
class adjacencyList {
public:
explicit adjacencyList(int size);
void buildGraph(Edge inEdge);
void print();
[code].....
View 6 Replies
View Related
Dec 28, 2014
I am trying to practice different concepts in C++ programming. Following is the program which compile successfully but gives seg fault at runtime.
#include <iostream>
#include <string.h>
using namespace std;
class A {
char *name;
int i,j;
const double k;
static float l;
int &m;
[Code] ....
View 5 Replies
View Related
Mar 9, 2013
I've received a segmentation fault in this part of code:
Code:
for (; str[i] != '