I have an assignment in which I have to accept an input from the user. I can't use a linked list, only an array, so my plan is:
Alloc some memory.
If we need to realloc, meaning that I reached the number of cells allocated:
Try to realloc. If…
The following are two functions in which the first one tries to allocate and subsequently reallocate memory for an array of pointers depending on the count value.
The second function tries to concatenate the last string onwards to the first string…
I think I know but I don't want to continue my work being incorrect.
Most examples you see are...
char* temp;
char* temp1;
temp = malloc(10, sizeof(char);
temp1 = realloc(temp, 11*sizeof(char));
Now I am assuming that you don't use...
temp =…
I would like to know why I can't reach to increase my array size by only one in a while loop.
Here is my code :
void pb_memory(void){
printf("ERROR : memory problem !\n");
system("PAUSE");
exit(EXIT_FAILURE);
}
int main(int argc, char…
I'm new in programming in C and I got 2 problems. I have two string, then I need to split them into words and find out if both strings contains same words. I will explain it with my code.
Input:
"He said he would do it."
"IT said: 'He would do…
I'm currently helping a friend with his assignments from his university, and have a moral dilemma regarding the behaviour of realloc when passing a NULL pointer (manuals say it should work exactly as a normal malloc).
So here's the code:
#include…
Issues with reallocing the items list. I am trying to add items into the testList structs items, but i am getting memory address errors when trying to add or print the values for the individual ListItems. Any help would be greatly…
new[] doesn't support change the size of allocated memory, does it?
For example, I allocated memory with new[] for buffer (array of char) and I want to get the additional memory.
Should I use malloc/realloc instead in this case?
I'm trying to get unlimited input from user, using realloc. this is what i've done so far:
int getCharactersFromUser(char* arr,char terminator)
{
char c = getch();
int length =0;
while(c!=terminator)
{
arr = realloc(arr, sizeof…
I have a struct as follows:
typedef struct somefruits{
struct pine abc;
int xyz;
}pm;
struct pine
{
unsigned char *ch;
unsigned char *data;
unsigned int a;
}
int function(unsigned int nfruits, pm **outfruits)
{
pm *fruits =…
i want to repair one error..
Valgrind says me this:
==9203== 1 errors in context 1 of 1:
==9203== Conditional jump or move depends on uninitialised value(s)
==9203== at 0x4C2D64A: strncat (in…
When ever the program finds a row in witch the first element's last number and the last element's last number divide by 2, then it should add other row to the matrix. I need to do this using dynamic allocation. Here is the code:
#include…
I am scanning lines from a textfile and putting elements into specific arrays, sscanf is working fine and inserting variables into arrays as well BUT printing out first element of string array result in segmentation fault(printing works for first…