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

C :: Segmentation Fault When Try To Read In The Lines Of File

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

C/C++ :: Seg Fault In Merge Function

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

C :: Segmentation Fault In Call To Recursive Function

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

C :: Segmentation Fault On 2nd Call Of Specific Function

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

C++ :: Segmentation Fault - Memory Error When Looping Over Function?

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

C :: Possible To Read Text Form Keyboard Using Read Function?

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

C :: Function That Sorts Dictionary List Alphabetically - Segmentation Fault (core Dumped)

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

C++ :: Function To Read HEX And Print ASCII?

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

C/C++ :: Read Numbers From A File Into Another Function?

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

C/C++ :: Function To Read Scores Into Array?

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

C :: File Write And Read As A Function Error

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

C++ :: Read Function - Compare And Assign Variables

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

C :: 1D Dynamic Array Crashes When Read From File Into A Function

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

C++ :: ReadFile Function Cannot Read Entire Executable File

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

C++ :: Using Fgets To Read In A String - No Conversion Function Error

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

C :: Function To Read A Text File - Incompatible Pointer Type

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

C/C++ :: Read From File / Assign As String And Call Function As Argument

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

Visual C++ :: Read JPG As Binary In MFC App And Send To JavaScript Function In HTML Page?

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

C++ :: Seg Fault Run Errors

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

C++ :: Strcpy Gives Seg Fault

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

C :: Seg Fault Using Logical OR On For Loop

Mar 9, 2013

I've received a segmentation fault in this part of code:

Code:
for (; str[i] != '' || str[i] != ' '; i++) {
result[result_pos] = str[i];
result_pos++;
}

which, should mean:

Code: If str[i] is not equal to NULL character nor ' '; then, keep printing the chars within the word to variable result.

To understand what the function does, here's the whole code:

static char result[999];
/* char *split_word(const char *str, long n);
* Splits a string word-by-word. Where N is the word number. */
char *split_word(const char *str, long n) {

[Code]....

I'm trying to accomplish an easier way round to split string by word than using "strtok_r()". It might sound like "re-inventing the wheel", but... i will try to make it neat later.

The code looks okay, why would it segfault?

View 7 Replies View Related

C :: Catch Segmentation Fault With GDB

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

C :: Seg Fault When Adding To List

Apr 3, 2013

I am currently working on a program and Originally I was to create a bash program to extra information from youtube and create a table of users, views, titles, duration, etc. (I sent each to a txt file)..Then I was to create a C program to use the extracted information. In this case Users and read in the conents of user.txt and construct a linked list to hold the information. Then print from the Linked list.I managed to do that,

Code:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LINE_LENGTH 100
void build_a_lst(), print_a_line(), print_lst();
void insert_at_end();
}

[code]...

What I have to do now is start reading in The other files and construct a table. And radix sort it by views. But to get to the radix sort part I get stuck on reading in all the files correctly and having the linked list hold them. I keep getting seg faults when I change my code.

View 3 Replies View Related

C :: Why Program Keeps On Getting Segmentation Fault

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

C :: Keep Getting Segmentation Fault Error

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







Copyrights 2005-15 www.BigResource.com, All rights reserved