I have an array of pointers (char**) which contain some strings. The array ends with an empty string ('\0'). I am supposed to search for a specific word in that array of strings and delete the whole line (ofc using realloc and shortening the array…
I struggle with pointers in C. I need to put first element of each line into an array.
Important parts :
char shipname[10];
char **shipTable = NULL;
while ( fgets( line,100,myfile) != NULL ) {
sscanf(line, "%s %lf %lf %lf %lf", shipname,…
I have have matrix that is dynamically allocated depending on the input. One line of input is one row in the matrix. Allocation ends with the EOF. The problem is, if I enter more than one row, valgrind show this.
I really dont know what is wrong.…
I'm trying to make this code work, but I cannot see why it crashes. It is supposed to read data from a file, and put it sorted (insertion sort) in a vector. proc is a vector of Process_t, proc.name is a char[10], proc[0] is inserted before (hard…
I'm having an unfixable problem at realloc statement in main.
Please help me: I'm trying to make a file into a vector of lines.
error: * glibc detected ./a.out: realloc(): invalid next size: 0x085d9018 **
?
thanks.
#include
#include…
I'm trying to get an expression from the user and put it in a dynamically created string. Here's the code:
char *get_exp() {
char *exp, *tmp = NULL;
size_t size = 0;
char c;
scanf("%c", &c);
while (c != EOF && c != '\n') {
…
I'm having an issue with pointers. I've read through 30+ posts on this subject and none match my setup. Here's what I'm trying to do:
void doSomething(myStruct **myList)
{
resizeMyList(myList,5);
myList[0] = '42';
myList[1] = '43'; //…
I have a problem with my program to get it run correctly.
here is the code:
#include
#include // for EXIT_SUCCESS and EXIT_FAILURE
#include
#include
void ReadFile(FILE* file) {
unsigned lines = 0;
…
Another one in my series of problems with this code. I have below function which is comparing arg with every string in the array of strings reference :
char compare(char *arg)
{
int iter=0;
char retchar='0';
while(iter <…
The following code loads in a text file called gasses.txt that has 16 terms, each on its own line, and stores these terms one at a time in the buffer search_terms.
#define MAX_LINE_LEN 40
FILE *dict_fp;
int term_len;
int j;
size_t…
I have written this function in C (function should receive a char*, allocate space necessary, and insert character given a pointer to the index of character behind the pointer)
void add_to_str(char *character, char ** string, int* index)
{
//we…
I have made a library program to store movies in and using dynamic memory allocation for my struct array without success. Adding the first record (movie) works fine, but after the second the values are just messed up characters.
There is not really…
I have created this small program to reverse a sentence.
So given: a b c d
It will give: d c b a
This works fine, until I add an extra letter. If I try "a b c d e" it will fail at the last one with the error
realloc(): invalid next size:…
I was writing a function that allow someone to expand an array of char*, and while doing some test I noticed that when I put more than 3 elements, the second one become something corrupted.
This is the function itself:
void…