Guest User

Untitled

a guest
Jan 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. char **string_pool;
  2.  
  3. string_pool = malloc( sizeof(char *) * 1024);
  4.  
  5. scanf("%[^n]s", &string_pool[index]);
  6.  
  7. printf("gets %sn", &string_pool[index]);
  8.  
  9. push 1
  10. read
  11. gets
  12.  
  13. case GETS: {
  14. int index = popv(); // index is already on top of the stack
  15. int strl = strlen(&string_pool[index]);
  16.  
  17. printf("gets %s with a length of %dn", &string_pool[index], strl);
  18. // pseudo code
  19. // push each char as integer on the stack
  20. foreach(char in string_pool[index]) push((int)char);
  21.  
  22. break;
  23. }
  24.  
  25. case READ: {
  26. int index = popv();
  27. scanf("%[^n]s", &string_pool[index]);
  28. break;
  29. }
  30.  
  31. case WRITE: {
  32. int index = popv();
  33. printf("%s", &string_pool[index]);
  34. break;
  35. }
  36.  
  37. string_pool[0] = malloc( 100 );
  38.  
  39. char **string_pool;
  40. string_pool = malloc( sizeof(char *) * 1024);
  41.  
  42. #define MAXCHR 2048
  43. ...
  44.  
  45. char buffer[MAXCHR];
  46.  
  47. fputs ("enter string: ", stdout);
  48. if (fgets (buffer, MAXCHR, stdin) == NULL) {
  49. fputs ("(user canceled input.)n", stderr);
  50. return 1;
  51. }
  52.  
  53. size_t len = strlen (buffer); /* get the length of input (with 'n') */
  54. if (len && buffer[len - 1] == 'n') /* trim the 'n' from end */
  55. buffer[--len] = 0; /* by overwriting with nul-character */
  56.  
  57.  
  58. string_pool[index] = malloc (len + 1); /* allocate storage for buffer */
  59. if (string_pool[index] == NULL) { /* validate allocation */
  60. perror ("maklloc-string_pool[index]"); /* handle error */
  61. return 1; /* or break read loop; */
  62. }
  63. /* copy buffer to string_pool[index], advance index */
  64. memcpy (string_pool[index++], buffer, len + 1);
  65.  
  66. int len = strlen(string_pool[index]);
  67.  
  68. char *ptr = string_pool[index];
  69. while(*ptr){
  70. //use *ptr
  71. ptr++;
  72. }
  73.  
  74. scanf("%[^n]s", string_pool[index]);
  75.  
  76. string_pool = malloc( sizeof(char *) * NO_STRS);
  77. for(int i=0;i<NO_STRS; i++)
  78. string_pool[i] = malloc(sizeof(char) * STR_LEN);
Add Comment
Please, Sign In to add comment