Hello, I have a question maybe more conceptual than practical, about the char variables. Suppose the next scenario
It works well, or for that sample situation it works well. My question is about the 2nd line on the 'test()' function: the char name[size], will do a 'malloc' each function call (or something internal like a mem allocation)? If yes, how can I know when there's enought memory (like the 'malloc' that returns null value)? Should I have to test if the buffer created is null? (I'm afraid that it will crash the program directly).Code://compiled as *c with MingW on DevCpp IDE #include <conio.h> #include <stdio.h> void test(char *txt,int i,int f) { int q; char bff[f-i+1]; for(q=0;q<(f-i);q++) { bff[q]=txt[q+i]; } bff[q]='\0'; printf("%s\n",bff); } int main() { test("That's a test.",0,6); test("That's a test.",7,8); test("That's a test.",9,13); getch(); return 0; }
Thank's in advance
Niara



LinkBack URL
About LinkBacks



CornedBee
