C :: Appcrash Segmentation Fault Char Inside Struct
Apr 24, 2013Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct info info;
[Code] ....
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct info info;
[Code] ....
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.
I need to take info in the following format (no blank/skipped lines):
last name, first name street address city, state zip code
And dynamically allocate space for it. I need to use structs, and I need to use an array of pointers to structs to point to them. I know I probably have quite a few problems with my code, but so far, I am able to store and print back the data without issue. In the following code, I only make the loop run 3 times just so I can test it with manual input into the console, but eventually the max will be 50, or until end of input (will be doing IO redirection with a txt file).
Like I said, I can store and print the data fine, but am getting a segmentation fault when trying to sort the info.
Code:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
struct addressBook{
char name [50];
char streetAddress [50];
[Code] ....
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)) != '