allocate « string « C Array Q&A

Home
C Array Q&A
1.bit
2.Byte
3.char
4.class
5.Development
6.Dimensional Array
7.dynamic
8.element
9.find
10.index
11.initialization
12.Integer
13.length
14.loop
15.memory
16.Operation
17.pointer
18.Print
19.size
20.Sort Search
21.string
22.struct
23.variable
C Array Q&A » string » allocate 

1. C tiny, pre-allocated array does not overrun    stackoverflow.com

I was expecting a segfault with this code:

char * foo (char my_ascii[10])
{
  strcpy (my_ascii, "0123456789");

  return my_ascii;
}

char bar[2];

printf("%s\n", foo (bar));
Because bar reserves a 2-char array in the stack, and ...

2. Fastest way possible to allocate an array of strings    stackoverflow.com

I have a function which takes an array of strings (buffer) and needs to increase its size. So I invoke a realloc

temp = (char**) realloc (buffer, newSize * (sizeof(char*)));
if (temp == NULL)
 ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.