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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:20:34+00:00 2026-06-14T05:20:34+00:00

edit – i figured out the arithmetic error but I still have the return

  • 0

edit – i figured out the arithmetic error but I still have the return error

For some reason my program is giving me two errors. First error is that the “return” at the end of each of my methods() are not ending the method and bring me back to main. My second question is at line 23 where pfNum = mainSize/pageSize; is giving me a “SIGFPE, arithmetic exception” not sure why both of these are occuring can anyone help me out?

Thanks

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

/* Define page table as dynamic structure containing virtual page and page frame 
   and initialize variable as pointer to structure */
struct table{
    int vp;
    int pf;
}*pageTable = NULL;
/* Declare global var's */
int mainSize,pageSize,policy,pfNum;
/**********************************************************************/
void option1(){
/* Declare local var's */
    int k;
/* Prompt for main memory size, page size, and replacement policy */
    printf("Enter main memory size(words): ");
    scanf("%d",&mainSize);
    printf("Enter page size(words/page): ");
    scanf("%d",&pageSize);
    printf("Enter replacement policy(0=LRU, 1=FIFO): ");
    scanf("%d",&policy);
    pfNum = mainSize/pageSize;
/* Allocate and initialize page table based on number of entries */
    pageTable = malloc(pfNum *sizeof(pageTable));
    for(k=0;k<pfNum;k++){
        pageTable[k].vp=-1;
        pageTable[k].pf=k;
    }
return;
}
/**********************************************************************/
void option2(){
/* Declare local var's */
    int va,page,offset,i=0,temp;
/* Prompt for virtual address */
    printf("Enter virtual memory address to access: ");
    scanf("%d",&va);
/* Translate virtual mem addr to virtual page and offset*/
    page = va/pageSize;
    offset = va%pageSize;
/* Check for end of table, unallocated entry, or matched entry in table 
and update table appropriately; while none of three cases, keep looping */

    while(i<pfNum && pageTable[i].vp!=1 && pageTable[i].vp!=page)
        i++;
    if(i<=pfNum){
        int j;
        temp = pageTable[0].pf;
        for(j=1;j<pfNum;j++)
            pageTable[j-1]=pageTable[j];
        pageTable[j].vp=page;
        pageTable[j].pf=temp;
        printf("Page Fault!");
    }
    else if(pageTable[i].vp==-1){
        pageTable[i].vp = page;
        printf("Page fault!");
    }
    else if(pageTable[i].vp==page){
        temp = pageTable[i].pf;
        int l,address;
        for(l=i+1;l<pfNum-1;l++)
            pageTable[l-1]=pageTable[l];
        pageTable[l].vp = page;
        pageTable[l].pf = temp;
        address = (temp*pageSize)+offset;
        printf("Virtual address %d maps to physical address %d",va,address);
    }
 return;
}
 /**********************************************************************/
void option3(){
 /* Declare local var's */
    int u;
    for(u=0;u<pfNum;u++ && pageTable[u].vp!=-1)
        printf("VP %d --> PF %d",pageTable[u].vp,pageTable[u].pf);
 /* Print out each valid virtual page and page frame pair in table */

 return;
}


 /**********************************************************************/
 int main(){
 /* Declare local var's */
    int choice;
 /* Until user quits, print menu of options, prompt for user input, and select     appropriate option */
    printf("/n");
    printf("Virtual memory to Main memory mapping:\n");
    printf("--------------------------------------\n");
    printf("1) Set parameters\n");
    printf("2) Map virtual address\n");
    printf("3) Print page table\n");
    printf("4) Quit\n");
    printf("\n");
    printf("Enter Selection: ");
    scanf("%d",&choice);
    printf("\n");
    while(choice!=4){
        if(choice==1)
            option1();
        else if(choice==2){
            option2();
        }
        else if(choice==3)
            option3();
    }
    printf("Goodbye. Have a nice day.");
return 1;
}
  • 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-14T05:20:35+00:00Added an answer on June 14, 2026 at 5:20 am

    The “SIGFPE, arithmetic exception” exception is most likely caused by division by zero.

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

Sidebar

Related Questions

Edit: I think I figured out the solution, but I'm still interested to know
Edit (updated question) I have a simple C program: // it is not important
EDIT: Ive edited my code a little thanks to Alexander's advice, but im still
EDIT: See my answer below--> I am wanting to have a view that when
EDIT : It turned out that this can only be done through an external
EDIT : I've gotten the famous question badge with this question, so I figured
EDIT: Sorry about ellipsis that's not what I actually have. For declaring an array
EDIT: I have reworded the title question slightly, and adjusted the text to respond
EDIT I don't know is it important, but destination triangle angles may be different
EDIT: I have been using Postgres with PostGIS for a few months now, and

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.