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

  • SEARCH
  • Home
  • 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 8302303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:15:25+00:00 2026-06-08T17:15:25+00:00

I built a stack data structure, which has a peek method. The compiler is

  • 0

I built a stack data structure, which has a peek method. The compiler is giving me a warning: initialization makes pointer from integer without a cast warning when calling peek in main. Here is what I have:

stack.h:

struct stack_elem {
    struct stack_elem *next;
};

struct stack {
    struct stack_elem *top;
};

void stack_init(struct stack *stack);
int isEmpty(struct stack *);
struct stack_elem * peak(struct stack *);

And its implementation:

void stack_init(struct stack *stack) {
    stack->top = NULL;
}

int isEmpty(struct stack *stack) {  
    if (stack->top == NULL) 
        return 1;
    else
        return 0;
}

struct stack_elem * peek(struct stack *stack) { 
    if (isEmpty(stack) == 1)  
        return NULL;
    else
        return stack->top;
}

In my main.c, I define stack as follows:

struct stack stack;
stack_init(&stack);

and call peek:

struct stack_elem * elem = peek(&stack);

This line throws the warning. The weird thing here is that I used to import stack.c into main.c and just compile with $ gcc main.c. This had absolutely no errors. Now I changed the import to stack.h, and I am compiling with $ gcc main.c stack.c which throws the warnings. Running it also segfaults (which it didn’t beforehand).

  • 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-06-08T17:15:27+00:00Added an answer on June 8, 2026 at 5:15 pm

    Change:

    struct stack_elem * peak(struct stack *);
    

    To:

    struct stack_elem * peek(struct stack *);
    

    : )

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

Sidebar

Related Questions

My app some times crashes at start-up. In stack-trace only messages from built-in frameworks.
My question can be asked in two different aspects: one is from data structure
I have just noticed that my simple program has its data and stack segments
Background I am working with a monad built of a stack of transformers one
I am trying to build the ohNet UPnP stack from openhome.org for execution on
I built a php script to output data posted in a form, but I
Project A contains a WPF Window (Data Entry Form) with a stack panel of
I need to find a data structure that meets these requirements: can build it
I'm looking for a web service testing framework that has a good built in
Something really weird has happened to my source code. The application always built successfully,

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.