I don't get it. I am looking since hours on following function and don't get why I get a memory fault when walking through the array in the end. If I don't walk through it, it runs without error. The function should split the input string first by…
I have:
char *data = malloc(file_size+1);
I also have strings such as char *string = "string1".
I want to be able to realloc memory to data whenever I'm about to add another string to data. What would be the best way to do this in C, I've seen…
I'm quite new to C. I'm trying to write a code that finds a string in a I/O stream, and I don't understand what I'm doing wrong. I know the error is probably in the large while loop (in the code below).
I want the function to return the location in…
EDIT Thanks Joachim. Used the function signature as you pointed out, and passed the address of my strings in. Inside the function, I did the realloc() using *currBuffer, and placed the values into the string using (*currBuffer)[lenBuffer] ....…
I'm trying to read a file into an array of strings using getline() and realloc(). I have used very similar code in the past for tokenizing strings and everything worked correctly. I'll consider the sample input file as
1
2
3
4
5
Here's the…
Im developing a C code to do a GET request and handle variable size response.
I use realloc to resize the heap chunk where i am storing the response. The problem is that i am getting an error related with the CrtIsValidHeapPointer function of the…
Please look at the following code
char *line = (char *) malloc(100);
char *newline,*source = line;
int size=100;
newline = realloc ( line , size +=size);
// assuming that newline has been successfully assigned the demanded memory and line is …
i am writing a file copy program,in which i faced difficulty regarding realloc().
Please look at the following snippet (which i write to understand the working of realloc()):-
int main(){
char *p =(char *) malloc ( 10 ),*t;
p = "this is";
…
I have a char* within a "news" struct like this:
typedef struct news{
char *name;
}news;
I read from a file some text (in example I have ever the same line:hello). For the main and my function i wrote this code:
int insert(news **note, char…
I have class Citizen { string name,address ... } and then I have class TaxRegister.
class TaxRegister
{
public:
bool Add_citizen ( const string& name, const string& addr );
private:
static const int m_Size=1000;
int…
In my program, I receive text from a .txt file. Here is an example of a line of text:
12X15 de3 ds4 dn9 g2,7 m5,9 m3,1 h2,2
I am trying to use strtok() to break up each chunk of text; I will then put each chunk as an element in an array. So an…
Admittedly what I was trying to do was at best educated guess work.
I have an array of strings, and I was trying to account for if someone entered a string that was too large, or the array received too much input (it needs to be dynamic for what I'm…
I need to get an unknown amount of strings from the user (via keyboard) and set an array of string pointers so that it will point to all the strings entered.
I defined a variable char tmp_strng[] to hold the string the user enters using the…