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 8237029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:20:05+00:00 2026-06-07T19:20:05+00:00

The following is a problem which i encountered while writing a program where i

  • 0

The following is a problem which i encountered while writing a program where i prompt a user to input as many values as i want, and then i print the results for each integer thus entered.

I was suggested to use dynamic memeory allocation by https://stackoverflow.com/users/319824/gcc in my last question How to test my program against an input test case file.


My code is as follows:

#include <stdio.h>
#include <stdlib.h>

struct node
{
int data;
struct node *next;
}*start;

void insertatend(int d)
{
struct node *n;
n=(struct node *)malloc(sizeof(struct node));
n->data=d;
n->next=NULL;

if(start==NULL)
{
    start=n;
}

else
{
    struct node *tmp;
    for(tmp=start;tmp->next!=NULL;tmp=tmp->next);
    tmp->next=n;
}

}

int max(int  a,int b)
{
int c=(a>b)?a:b;
return c;
}

int maxCoins(int n)
{
int arr[n+1],i;
arr[0]=0;
arr[1]=1;
arr[2]=2;
arr[3]=3;

if(n>2)
{


for(i=3;i<=n;i++)
{
    int k= arr[(int)(i/2)]+arr[(int)(i/3)]+arr[(int)(i/4)];
    arr[i]=max(i,k);
}
}

 return arr[n];
}


int main(void)
{
int coins,i;
start=NULL;
struct node*p;

while(scanf("%d",&coins))
{
    insertatend(coins);
}

for(p=start;p!=NULL;p=p->next)
{
    printf("%d\n",p->data);
}

getchar();
return 0;
}

The program runs successfully. I am able to give any number of inputs, and if I try to break out by pressing CTRL + Z ,the program does not respond. Can’t I use dynamic memory allocation for problems like these ? And if yes, where am i wrong ?

  • 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-07T19:20:07+00:00Added an answer on June 7, 2026 at 7:20 pm
    while(scanf("%d",&coins))
    

    If you send CTRL+Z to your programme, scanf returns EOF, which is a negative number and not 0, so the contition evaluates to true and you’re in an infinite loop. Test

    while(scanf("%d",&coins) > 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive got the following problem. I have a model called user which has a
I encountered this problem while solving a practice test Consider the following code written
I encountered the following problem with MongoID. I've created two models which related by
I have encountered the following problem which proved to me that I know far
I'm writing a windows application in C++ and encountered the following problem when working
Consider the following problem: A multi-line string $junk contains some lines which are encoded
I've got following problem: (c#) There is some class (IRC bot), which has method,
I have the following problem. I have a class named A in which I
I have the following problem: I opened the activity A, from which I opened
I am having a strange problem which I don't understand. I have the following

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.