#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Exclamation PLEASE somebody help me!!


    Im sorry about the original post, that was my first.
    So, this is a program to be used in a bank as a organizer line.
    Everytime i add a person, at the time to show the queue, it just display the last one and set it to everyone, how to fix it?
    And on deleting person, how to show the name (like: "the person XXX was attended").

    The code is working but I need to fix those:
    Set the right name and show it when deleted.
    Thank you everyone!! :D

    Code below:
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    struct node{
    int priority;
    int info;
    struct node *link;
    }*front=NULL;
    
    void insert(char person[20], int person_priority);
    int del();
    void display();
    int isEmpty();
    
    main(){
    int choice,person_priority;
    char person[20];
    
    while(1){
    printf("1.Insert Person\n");
    printf("2.Attend Client\n");
    printf("3.Show Queue\n");
    printf("4.Exit\n");
    printf("Type choice : ");
    scanf("%d", &choice);
    
    switch(choice){
                   
    case 1:
    printf("Type persons name:");
    scanf("%s", &person);
    printf("Its Priority:\n1 Pregnant\n2 Older\n3 Standard: ");
    scanf("%d",&person_priority);
    insert(person, person_priority);
    system("cls");
    break;
    case 2:
         system("cls");
    printf("Person was attended",del());
    break;
    case 3:
         system("cls");
    display();
    
    break;
    case 4:
    exit(1);
    default :
    printf("Invalid Choice\n");
    }/*end of switch*/
    }/*end of while*/
    }/*end of main()*/
    
    void insert(char person[20],int person_priority){
    struct node *tmp,*p;
    
    tmp=(struct node *)malloc(sizeof(struct node));
    
    if(tmp==NULL){
    printf("No Memory available\n");
    return;
    }
    
    tmp->info=person;
    tmp->priority=person_priority;
    /*Starting list*/
    if( isEmpty() || person_priority < front->priority ){
    tmp->link=front;
    front=tmp;
    }
    
    else{
    p = front;
    while( p->link!=NULL && p->link->priority<=person_priority )
    p=p->link;
    tmp->link=p->link;
    p->link=tmp;
    }
    }/*end of insere()*/
    
    int del(){
    struct node *tmp;
    int person;
    if( isEmpty() )
    {
        
    printf("Empty Queue\n");
    exit(1);
    }
    
    else{
    tmp=front;
    person=tmp->info;
    front=front->link;
    free(tmp);
    }
    return person;
    }/*end of del()*/
    
    int isEmpty(){
    if( front == NULL )
    return 1;
    else
    return 0;
    
    }/*end of emtpy verification (isEmpty())*/
    
    void display(){
    struct node *ptr;
    ptr=front;
    if( isEmpty() )
    printf("Empty Queu\n");
    else{    printf("Line :\n");
    printf("Priority       Name\n");
    while(ptr!=NULL){
    printf("%5d        %5s\n",ptr->priority,ptr->info);
    ptr=ptr->link;
    }
    printf("\n\n\n");
    }
    }/*end of display() */
    Last edited by bmendes93; April 22nd, 2013 at 01:35 AM. Reason: Fix problems
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,381
    Rep Power
    1871
    Please edit your post and put [code][/code] tags around your code.
    Copy again from your code editor so indentation is preserved.

    Help me Obiwan Kenobi, you're my only hope
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,156
    Rep Power
    2222
    Nobody is going to bother to try to read that unreadable mess. Use code tags! Edit your post with code tags and formatted code.

    Also, nobody here has any idea at all what "but it comes a lot of bug" is supposed to mean. A description of the problem works a lot better than trying to force us to play guessing games with you.

    Before you go any further, you need to correct a lot of problems in your code. When I compile it with MingW gcc, this is what I get:
    C:\otros\dcw>gcc -Wall green.c
    green.c:17: warning: return-type defaults to `int'
    green.c: In function `main':
    green.c:21: parse error before character 0223
    green.c:21: missing white space after number `1.'
    green.c:21: stray '\' in program
    green.c:22: parse error before character 0223
    green.c:22: nondigits in number and not hexadecimal
    green.c:22: floating constant exponent has no digits
    green.c:22: missing white space after number `2.De'
    green.c:22: stray '\' in program
    green.c:23: parse error before character 0223
    green.c:23: nondigits in number and not hexadecimal
    green.c:23: missing white space after number `3.D'
    green.c:23: stray '\' in program
    green.c:24: parse error before character 0223
    green.c:24: nondigits in number and not hexadecimal
    green.c:24: missing white space after number `4.Q'
    green.c:24: stray '\' in program
    green.c:25: parse error before character 0223
    green.c:26: parse error before character 0223
    green.c:31: parse error before character 0223
    green.c:32: parse error before character 0223
    green.c:33: parse error before character 0223
    green.c:34: parse error before character 0223
    green.c:38: parse error before character 0223
    green.c:38: stray '\' in program
    green.c:46: parse error before character 0223
    green.c:46: stray '\' in program
    green.c: In function `insert':
    green.c:58: parse error before character 0223
    green.c:58: stray '\' in program
    green.c: In function `del':
    green.c:85: parse error before character 0223
    green.c:85: stray '\' in program
    green.c: In function `display':
    green.c:112: parse error before character 0223
    green.c:112: stray '\' in program
    green.c:114: stray '\' in program
    green.c:115: parse error before character 0223
    green.c:115: stray '\' in program
    green.c:118: parse error before character 0223
    green.c:118: nondigits in number and not hexadecimal
    green.c:118: nondigits in number and not hexadecimal
    green.c:118: stray '\' in program
    green.c: At top level:
    green.c:122: parse error before `}'

    C:\otros\dcw>
    Wait a minute here.
    printf(1.Insert\n);
    That is not the same as
    printf("1.Insert\n");
    A C compiler will recognize the "" quotation marks, but not that nonsense. What are you writing this with? Are you using a word processor instead of a text editor? I have never seen a foul-up like this before in all my life!

    What are you using to write this code? Replace all those weird word-processor quotation marks with regular good old ASCII double quotes. When I replace them all in my text editor and recompile, This is what I get:
    C:\otros\dcw>gcc -Wall green.c
    green.c:17: warning: return-type defaults to `int'

    C:\otros\dcw>
    main() is supposed to return int, so rather then trying to have it default to that, declare it explicitly. And don't forget to return 0 as the last statement in main().
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,156
    Rep Power
    2222
    Good, you figured out how to use code tags. Very very bad, you did not indent your code! The purpose of code tags is to preserve your code's indentation, thus preserving its formatting, thus keeping it readable.

    You also did not correct the declaration of main().

    What is the current status of your program? Also, was I right that you had used a word processor instead of a text editor?

    Further explanation of the problem which should clarify some of the error messages you were getting. Since you corrected the problem of the double quotes, I offer this short text from my reply as the example, since it contains a line of code from your original post which I had copied and pasted:
    Wait a minute here.
    printf(1.Insert\n);
    That is not the same as
    printf("1.Insert\n");
    Here is the hex dump of that text (produced by xxd):
    Code:
    0000000: 5761 6974 2061 206d 696e 7574 6520 6865  Wait a minute he
    0000010: 7265 2e0d 0a70 7269 6e74 6628 9331 2e49  re...printf(.1.I
    0000020: 6e73 6572 745c 6e94 293b 0d0a 5468 6174  nsert\n.);..That
    0000030: 2069 7320 6e6f 7420 7468 6520 7361 6d65   is not the same
    0000040: 2061 730d 0a70 7269 6e74 6628 2231 2e49   as..printf("1.I
    0000050: 6e73 6572 745c 6e22 293b 0d0a            nsert\n");..
    As you can see, the ASCII code for " is 0x22 (34 decimal). However, the ASCII codes for and are 0x93 and 0x94, respectively (147 and 148 decimal); BTW, only the first 128 codes (1-127) are standard, while ASCII codes 128-255 are "extended ASCII", of which that are several different decodings. Because of that, xxd only displays characters for 7-bit ASCII; all extended-ASCII codes are represented by a period. Note that neither nor is displayed, but rather they have been replaced by periods.

    The error messages of interest are:
    green.c:21: parse error before character 0223
    green.c:21: missing white space after number `1.'
    green.c:21: stray '\' in program
    which occur repeatedly. I chose the ones for the line that I just did a hex dump of.

    0223 is an octal number which is equivalent to the hex value 0x93, or 147 decimal. Octal numbers (base 8) are indicated by a leading zero and use the 8 digits ranging from 0 to 7. Hexadecimal numbers (base 16) are indicated by the prefix, "0x", and use the 16 digits ranging from 0 to 9 and from A to F (representing 10 through 15). Both number bases are used extensively in computer science since conversion between them and binary is extremely simple.

    So then, the first error says that it cannot figure out the since that is not a valid character in C syntax. It does not know that you intended that to start a string, so when it encounters the 1 it thinks it needs to start building a number, but then there's a letter immediately after it, which is contrary to C syntax. And then, still thinking that it's supposed to be scanning code, it encounters the \n, which is completely out of place in that "code".

    But by replacing those invalid characters with proper double quotes (ASCII code 34), it correctly identifies what is code and what is a string.

    And now you know the rest of the story.
    Last edited by dwise1_aol; April 23rd, 2013 at 11:09 AM.

IMN logo majestic logo threadwatch logo seochat tools logo