Infinite Input Buffer | C Programming Example

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

2 minor notes on the video:
#1 the 'else' in the program (when something else than -1 was entered) is not needed at all.
I would omit it.
#2 buffer=realloc(buffer, newsize); is a timebomb.
if realloc() fails (for whatever reason), you do not only have no new buffer,
you also lost your old buffer ... technically the old buffer is still there, but you
overwrote the pointer-variable holding the location.
So, use
newbuffer=realloc(oldbuffer, newsize)
followed by
if (newbuffer==NULL) { some errorhandling that might include oldbuffer }
else { oldbuffer=newbuffer; newbuffer=NULL; }

Rai_Te
Автор

Just came to C from higher level languages as a web developer. I was struggling with the idea of malloc and realloc and this just cleared everything up for me! Thanks!

punchedchunk
Автор

it's my second time watching this tutorial, and I just realized that it's a genius algorithm to increase the use of memory to instore data, to be processed. thank you

naboulsikhalid
Автор

Thank you Mr. for making the "Dynamic Memory Allocation" topic more understandable.

aknsagdic
Автор

Great tutorial. A missing point, it’s required to free the allocated memory at the end, when it’s not being used anymore.

ErginSoysal
Автор

as great as usual, the content is absolutely rich and fulfilling. Thank you

naboulsikhalid
Автор

if i'm correct, this behaves similarly to a vector list in c++ right?

zarifishmam
Автор

I might be missing something here, but it appears that malloc offers the structure of an array? Else, where does buffer inherit its structure [of an array] where it has elements?

EDIT: Disregard. You explain this in the first 5-10min of the malloc video. VERY COOL!

StreuB
Автор

This was very intersting. I understood that realloc is essentially reallocating memory in ram for the code.
What does malloc do? Does it initialise memory for the code?

Can we just create the code without allocating memory and then reallocate if our code output is big?☺️

SketchupGuru
Автор

Hi! Thank u for the video.
I have a question:
Is there any reason to learn c, to better umderstand c#/c++ or any other language that based on pure C?

samirprostov
Автор

What will happen when the hardware can't store values anymore?

war-cmmander
Автор

Hey I need help, am trying to understand ADT but it's like am getting the idea what can I do

vinmo
Автор

Nice, We can use the same idea to get infinite string from the user like this maybe :

char *infinite_line(void){
int size = 5;
char *line = (char*)malloc(sizeof(char) * size);
int c ;
int char_count = 0;
while((c = getchar()) != '\n'){
if(char_count == size){
size+=5;
line = realloc(line, sizeof(char) * size);
}
line[char_count] = c;
++char_count;
}
line[char_count] = '\0';
return line;
}

justcurious
Автор

make a video on how to use gtk+, to make user interface

vinmo
Автор

in real programming what can I do with bitwise knowledge?

vinmo
Автор

is c used to develop application that require a databases😁😁

vinmo
visit shbcf.ru