Note that there are some explanatory texts on larger screens.

plurals
  1. POStack of strings
    primarykey
    data
    text
    <p>Hi i have program here that accept int as value. i wanted to translate it to accept strings in array then. i have read about using struct but i couldnt get into it. i hope someone can help me getting into that without using struct i dont know where to start i want to keep this lines of code. </p> <pre><code>#include &lt;stdio.h&gt; #include &lt;ctype.h&gt; #include &lt;conio.h&gt; #include &lt;string.h&gt; #include &lt;stdlib.h&gt; int top = 0; int *stack = NULL; int size = 0; main() { int opt, num; char cont[] = { 'y' }; clrscr(); /* &lt;start Declaring Stack Size { */ printf("Stacking Program"); printf("\n\nData Size: "); scanf("%d", &amp;size); printf("\n"); /* } end&gt; */ /* &lt;start Allocates size of stack { */ if(size &gt; 0) { stack = malloc(size * sizeof(int)); if(stack == NULL) { printf("ERROR: malloc() failed\n"); exit(2); } } else { printf("ERROR: size should be positive integer\n"); exit(1); } /* } end&gt; */ while((cont[0] == 'y') || (cont[0] == 'Y')) { clrscr(); /* &lt;start Main Menu { */ printf("Stacking Program"); printf("\n\nData Size: %d\n\n", size); printf("MAIN MENU\n1. Pop\n2. Push\n3. Pick\n4. View\nChoose: "); scanf("%d", &amp;opt); printf("\n"); switch(opt) { case 1: pop(); break; case 2: if(top==size) { printf("You can't push more data"); } else { printf("Enter data for Stack[%d]: ", top+1); scanf("%d", &amp;num); push(num); } break; case 3: pick(); break; case 4: view(); break; default: printf("Your choice is not on the list."); break; } /* } end&gt; */ printf("\n\nDo you want continue\(Y\/N\)?"); scanf("%s", &amp;cont[0]); } free(stack); } pop() { int a; loading(); if(top &lt;= 0) { printf("Stack empty."); return 0; } else { top--; a=stack[top]; printf("\(Stack[%d] = %d\) removed.", top+1, a); } } push(int a) { stack[top]=a; top++; loading(); } pick() { loading(); if(top &lt;= 0) { printf("Nothing to display."); return 0; } else { printf("\(Stack[%d] = %d\) is the last data.", top, stack[top-1]); } } view() { int i; loading(); if(top &lt;= 0) { printf("Nothing to display."); return 0; } else { for(i=0;i&lt;top;i++) { printf("Stack[%d] = %d\n", i+1, stack[i]); } } } loading() { float i, x; float load; int loadarea[] = { 5000, 10000, 15000, 20000, 25000, 30000 }; int percentLoad; x=0; load=0; percentLoad = loadarea[random(5)]; gotoxy(26,11); printf("["); for(i=0;i&lt;25;i++) { x = i+27; gotoxy(x, 11); printf("="); delay(percentLoad); gotoxy(51,11); printf("]"); gotoxy(53,11); load=(i/25)*104.5; if(load&gt;100) load = 100.00; printf("%.2f\%",load); } delay(60000); for(i=0;i&lt;60;i++) { printf("\b \b"); } printf("\n"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload