Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Compiler Design in C

Compiler Design in C

Scheduled Pinned Locked Moved C / C++ / MFC
designdata-structureshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DarkSorrow38
    wrote on last edited by
    #1

    I have compiler design in C practicals and i have encountered a problem. This goes as : We have to take n number of productions(string) from user. Each production is of different size. I want the array size for each production to be dynamic with exact size as that of the entered string. There should not be any blank elements in array as it would spoil the output. How this can be achieved. I am someone who not so good in C.

    _ 1 Reply Last reply
    0
    • D DarkSorrow38

      I have compiler design in C practicals and i have encountered a problem. This goes as : We have to take n number of productions(string) from user. Each production is of different size. I want the array size for each production to be dynamic with exact size as that of the entered string. There should not be any blank elements in array as it would spoil the output. How this can be achieved. I am someone who not so good in C.

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      You could create an array of pointers if you know the value of n at compile time.

      char *strings[50];

      Now as you save each string to this array allocate the size.

      strings[count] = malloc(sizeof(string) + 1);
      strcpy(strings[count], string);

      If the value of n is not known at compile time, create a pointer to a pointer.

      char **strings;

      When you get the value of n, allocate the array.

      *strings = malloc(sizeof(char*) * n);

      Allocation for each string is the same as above. Don't forget to increment the count variable after to store every string.

      «_Superman_» I love work. It gives me something to do between weekends.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups