Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6213371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:41:05+00:00 2026-05-24T06:41:05+00:00

I have the following code, and on line 68, I’m getting a format error.

  • 0

I have the following code, and on line 68, I’m getting a format error.
stack.c:68: warning: format ‘%e’ expects type ‘float *’, but argument 3 has type ‘double *’

On the input push 4, it gets a segfault. Not sure if they’re related. Please help!

#include <stdio.h>
#include <stdlib.h>
#define OFFSET '0'
#define DIM1 7
#define DIM2 5
#define RES_SIZE 1000

//typedef double double;

typedef struct {
  double *contents;
  int maxSize;
  int top;
} stackT;

void StackInit(stackT *stackP, int maxSize) {
    double *newContents;
    newContents = (double *)malloc(sizeof(double)*maxSize);
    if (newContents == NULL) {
        fprintf(stderr, "Not enough memory.\n");
        exit(1);
    }

    stackP->contents = newContents;
    stackP->maxSize = maxSize;
    stackP->top = -1;
}

void StackDestroy(stackT *stackP) {
    free(stackP->contents);
    stackP->contents = NULL;
    stackP->maxSize = 0;
    stackP->top = -1;
}

int StackIsEmpty(stackT *stackP) { return stackP->top < 0; }

int StackIsFull(stackT *stackP) { return stackP->top >= stackP->maxSize-1; }

void StackPush(stackT *stackP, double element) {
    if(StackIsFull(stackP)) {
        fprintf(stderr, "Can't push element: stack is full.\n");
        exit(1);
    }
    stackP->contents[++stackP->top] = element;
}

double StackPop(stackT *stackP) {
    if(StackIsEmpty(stackP)) {
        fprintf(stderr, "Can't pop element: stack is empty.\n");
        exit(1);
    }
    return stackP->contents[stackP->top--];
}

void StackShow(stackT *stackP) {
    int i;
    printf("[ ");
    for (i = 0; i < stackP->top - 1; i++) {
        printf("%e, ", stackP->contents[i]);
    }
    printf("%e ]\n", stackP->contents[stackP->top - 1]);
}

double shell(char* s1, double arg) {
    printf(">   ");
    scanf("%s %f%*c", s1, &arg);
    return arg;
}

int main() {
    //char cmds[DIM1][DIM2] = {{"push"}, {"pop"}, {"add"}, {"ifeq"}, {"jump"}, {"print"}, {"dup"}};
    stackT res;
    StackInit(&res, RES_SIZE);
    char cmd[DIM2]; double arg = 0;
    arg = shell(cmd, arg);
    if (StringEqual(cmd, "push")) {
        StackPush(&res, arg);
        StackShow(&res);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:41:06+00:00Added an answer on May 24, 2026 at 6:41 am

    Just had a quick look on you code , I think after pushing the first element your stack top pointer is set to 0 .
    Now in you StackShow() method you are accessing an invalid memory location from this line :

     printf("%e ]\n", stackP->contents[stackP->top - 1]); // accessing invalid location stackP->contents[-1] 
    

    This is an off-by-one error for the array contents .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a line of code that gets the following error when run through
I have following line of code for jsp tag <input name=UnicodeVirtualKey class=btn type=button value=&#x0A85;
I have the following code: void foo() { vector<double> v(100,1); // line 1 //
I have the following line of code in a link on my webpage: <a
I have the following line of code: public bool dcpl_radar() { if (radar ==
I have the following line of code called very often: var configValue = System.Configuration.ConfigurationManager.AppSettings[ConfigValueKey];
I have the following line of code. <%= Html.Encode(string.Join(, , item.company1.companies.Select(x => x.company_name).ToArray())) %>
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
Suppose I have a line of code that starts like the following: Func1(Func2(Func3 Is
I have a line of PHP code that does the following: $xml = <xml><request>...[snipped

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.