error message code

This is a discussion on error message code within the C Programming forums, part of the General Programming Boards category; I get help with the cast and it should run I am using two compilers one works and doesn't leave ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    12

    error message code

    I get help with the cast and it should run I am using two compilers one works and doesn't leave the output window open the other still gives me an error. Cut and paste this and see if it runs as is for you.




    #include <stdio.h>
    #include <stdlib.h>
    #define NULL 0

    struct node
    {
    int number;
    struct node *next;
    };

    struct node *pageFaults, *p, *q, *z, *n;
    int num=0;
    void ChangeFrames(void)
    {
    int count, x, y, r, m, tempx, frames[10], pages[40];
    count=0;

    /* creates the reference string randomly */
    for(x=0; x<=39; x++)
    {
    if (frames[0] == 0)
    {
    frames[0] = pages[y];
    count++;
    }
    /* Next page frame gets filled #2 */

    if (frames[1] == 0 && frames[0] != 0 && frames[0] != pages[y])
    {
    frames[1] = pages[y];
    count++;
    }
    /* Next page frame gets filled #3 */
    if (frames[0] !=0 && frames[1] !=0 && frames[0] != pages[y])
    if (frames[1] != pages[y] && frames[2] == 0)
    {
    frames[2] = pages[y];
    count++;
    }
    /* Next page frame gets filled #4 */

    if (frames[0] != 0 && frames[1] !=0 & frames[0] != pages[y] && frames[1] != pages[y])
    if (frames[2] != 0 && frames[2] != pages[y] && frames[3] == 0)
    {
    frames[3] = pages[y];
    count++;
    }
    /* Next page frame get filled #5 */

    if (frames[3] != 0 && frames[0] != pages[y] && frames[1] != pages[y])
    {
    if (frames[2] != pages[y] && frames[3] != pages[y] && frames[4] == 0)
    {
    if (frames[2] != 0 && frames[1] != 0 && frames[0] != 0)
    {
    frames[4] = pages[y];
    count++;
    }
    }
    }
    /* Next page frame gets filled #6*/

    if (frames[4] != 0 && frames[0] != pages[y] && frames[1] != pages[y] && frames[0] != 0)
    {
    if(frames[2] != pages[y] && frames[3] != pages[y] && frames[4] != pages[y])
    {
    if (frames[5] == 0 && frames[3] != 0 && frames[2] != 0 && frames[1] != 0)
    {
    frames[5] = pages[y];
    count++;
    }
    }
    }
    /* Next page frame get sfilled #7 */

    if (frames[5] != 0 && frames[6] == 0 && frames[0] != pages[y] && frames[4] != pages[y])
    {
    if (frames[2] != pages[y] && frames[3] != pages[y] && frames[4] != pages[y])
    {
    if (frames[5] != pages[y] && frames[4] != 0 && frames[3] != 0 && frames[2] != 0)
    {
    if (frames[1] != 0 && frames[3] != 0 && frames[4] != 0 && frames[0] != 0)
    {
    frames[6] = pages[y];
    count++;
    }
    }
    }
    }
    /* Next page frame get filled #8 */

    if (frames[6] != 0 && frames[7] == 0 && frames[0] != pages[y] && frames[1] != pages[y])
    {
    if (frames[2] != pages[y] && frames[3] != pages[y] && frames[4] != pages[y])
    {
    if (frames[5] != pages[y] && frames[6] != pages[y] && frames[2] != 0 && frames[0] != 0)
    {
    if (frames[1] !=0 && frames[3] != 0 && frames[4] != 0 && frames[5] != 0)
    {
    frames[7] = pages[y];
    count++;
    }
    }
    }
    }
    /* Next page frame gets filled #9 */

    if (frames[6] != pages[y] && frames[7] != 0 && frames[0] != pages[y] && frames[1] != pages[y])
    {
    if (frames[2] != pages[y] && frames[3] != pages[y] && frames[4] != pages[y])
    {
    if (frames[5] != pages[y] && frames[6] != pages[y] && frames[7] != pages[y])
    {
    if (frames[6] != 0 && frames[5] != 0 && frames[4] != 0 && frames[3] != 0)
    {
    if (frames[2] != 0 && frames[1] != 0 && frames[0] != 0 && frames[8] == 0)
    {
    frames[8] = pages[y];
    count++;
    }
    }
    }
    }
    }
    /* Next page frame gets filled #10 */

    if (frames[6] != pages[y] && frames[7] != pages[y] && frames[0] != pages[y])
    {
    if (frames[2] != pages[y] && frames[3] != pages[y] && frames[3] != 0)
    {
    if (frames[5] != pages[y] && frames[6] != 0 && frames[2] != 0 && frames[8] != 0 && frames[7] != 0)
    {
    if (frames[9] == 0 && frames[8] != pages[y] && frames[5] != 0 && frames[4] != 0)
    {
    if (frames[0] != 0 && frames[1] != 0 && frames[2] != 0 && frames[3] != 0)
    {
    if (frames[5] != 0 && frames[1] != pages[y] && frames[4] != pages[y])
    {
    frames[9] = pages[y];
    count++;
    }
    }
    }
    }
    }
    }
    m = pages[y];

    /* Next the pages are evicted and swapped with new pages */

    if (frames[7] != 0 && frames[0] != 0 && frames[1] != 0)
    {
    if (frames[2] != 0 && frames[3] != 0 && frames[4] != 0 && frames[9] != 0)
    {
    if (frames[5] != 0 && frames[6] != 0 && frames[8] != 0)
    {
    if (frames[6] != pages[y] && frames[7] != pages[y] && frames[0] != pages[y] && frames[1] != pages[y])
    {
    if (frames[2] != pages[y] && frames[3] != pages[y] && frames[4] != pages[y] && frames[9] != pages[y])
    {
    if (frames[5] != pages[y] && frames[6] != pages[y] && frames[8] != pages[y])
    {
    if (num>9)
    {
    if (num==10)
    {
    pageFaults = (struct node *)calloc(1, sizeof(struct node));
    (*pageFaults).number=frames[0];
    (*pageFaults).next=NULL;
    q=pageFaults;
    }
    else
    {
    z = (struct node *)calloc(1, sizeof(struct node));
    (*z).number=frames[0];
    (*q).next=z;
    q=z;
    }
    }
    num++;
    frames[0] = frames[1];
    frames[1] = frames[2];
    frames[2] = frames[3];
    frames[3] = frames[4];
    frames[4] = frames[5];
    frames[5] = frames[6];
    frames[6] = frames[7];
    frames[7] = frames[8];
    frames[8] = frames[9];
    frames[9] = m;

    count++;
    }
    }
    }
    }
    }
    }
    }

    printf("Here are the frames at the end of the reference string\n");

    for( r=0; r<=9; r++)
    {
    printf(" %d", frames[r]);
    }
    printf("\nTotal number of page faults = %d\n", count);

    for(tempx = 0; tempx <= 39; tempx++)
    {
    printf(" %d", pages[tempx]);
    }
    }
    int main()
    {

    void changeFrames();

    printf("Pages evicted are:\n");
    p=pageFaults;
    n=pageFaults;
    num=0;
    while(p != NULL)
    {
    printf("%d", (*p).number);
    p = (*p).next;
    }
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    Dunno about anything else, but

    /* Next page frame gets filled #4 */

    if (frames[0] != 0 && frames[1] !=0 & frames[0] != pages[y] && frames[1] != pages[y])

    There is an & which should be a &&

    Also
    if (frames[0] == 0)
    {
    frames[0] = pages[y];
    count++;
    }

    The pages array and y are not initialised before you enter this loop.

    A very large/negative value for y will cause you array access problems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21