Advertisement
Guest User

hu

a guest
Jul 14th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. void allocate(unsigned int size1, unsigned int size2) {
  2.  
  3. // char array[size1][size2]; // Not possible
  4.  
  5. // Now, i need to allocate space in memory for that "array"
  6.  
  7. char *array = malloc(size1*size2); // This will allocate enough space
  8.  
  9. // But i need to access to each element like if it was a fixed array
  10.  
  11. // Like:
  12. // strcpy(array[0], "Hello world!");
  13.  
  14.  
  15. }
  16.  
  17. int main(int argc, char **argv) {
  18.  
  19. allocate(atoi(argv[1]), atoi(argv[2]));
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement