C++ :: Segmentation Fault In Input / Output Array
Sep 3, 2013
When I try to run the code, I get a segmentation fault core dumped, it returns 139 (0x8B)
The file it is pulling from is a list of numbers, but without the string, the output ends up going from values of ~70,000 to values around 50
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#define MAX 29656
using namespace std;
string el[MAX];
ifstream file1("results.txt");
ofstream file2("Energy1.txt");
[Code] ....
View 1 Replies
Oct 29, 2014
I need to distinguish between number (float) and other non number characters. I was trying to use this:
Code:
#include <stdio.h>
#include <ctype.h>
float Ax;
...
scanf("%f
",&Ax);
if (isdigit(Ax)) {....}
And whatever I type I receive "Segmentation fault". How can I detect that the float input is correct? Is there any built in function?
View 7 Replies
View Related
Aug 27, 2014
Write a program that reads in the names and the ages of ten people. Store these data in two arrays (make sure that the entered names are not longer than the array size you choose). Then produce a table of ten lines, with each line giving the name and age of a person along with the (positive or negative) deviation of that person's age from the average age. The code I wrote to fill in the arrays looks as follows
Code:
#include<stdlib.h>
#include<stdio.h>
int main()
{ // begin main()
// array length
[Code]....
When I compile it, it gives me warnings that few of the variables I declared aren't used, but that is not affecting the program at all. When I run the program, it allows me to pass the names and ages into the arrays, but when it comes to displaying them, I'm getting a 'Segmentation fault'. I used very similar code in Java to write the program, and it worked fine so what is the problem with C then?
View 8 Replies
View Related
Jun 4, 2013
i want to enter a URL in as a string, and extract just the URL part.
eg: Code: input: URL....
output: URL....
Input: URL....
output: URL....
part of our header file which we cannot edit (the url is always less than 140 characters):
Code:
char url[140];
function i am having problems with
Code: void init_url(char new_url[])
{
/*
This function sets the variable url to new_url and url_size to the number of characters in the url
It also initializes url_error_flag
}
[code]....
whenever i try a URL like the second one above with no '?' i'm getting a segmentation fault error which is becase i'm trying to access an invalid index. i'm not sure what an array is initialized to when i do not explicitly assign it anything, for example
Code:
char values[140] = {0};
i've read it depends on whether it is a global vs local array or something? i know this could all be fixed with simply assigning the array values to 0 but i'm not allowed to edit the header file.
View 11 Replies
View Related
Apr 20, 2013
This is a homework assignment where I have to read a file into a dynamically allocated 2d array. The file format is
10
Jim 3.6
Jake 4.0
Will 3.0
Sara 3.4
Mike 2.5
Ellen 2.9
Melissa 3.9
Eric 3.8
John 3.5
Beth 3.9
where 10 is the number of students followed by the students and the gpa's. There is more to the program but I have not implemented it yet because I am getting a segmentation fault. The output I am getting when I print the array is
Jim 3.6
Jake 4.0
Will 3.0
Sara 3.4
Segmentation fault
I can see where the problem lies. If I raise value for row when I am allocating the rows of the array, all of the names print. I just do not see why I need to. From my understanding the row * sizeof(char*) should give me enough room for 10 entrie.
Code:
#include <stdio.h>
#include <stdlib.h>
void sort();
int main()
[Code] .....
View 6 Replies
View Related
Jan 25, 2013
This function should replace all instances of a character in a given character array, while returning the amount of characters changed, but I keep getting a segmentation fault at the highlighted area.
I'm only supposed to use pointers so arrays are out of the question, and I don't think we are allowed to use the string.h library as well. How I could avoid something the segmentation fault or ways to fix it?
Code:
int replaceChars(char replace, char find, char *input) { int i, j;
//Finds length
for(i = 0; *(input + (i + 1)) != '