Double print

This is a discussion on Double print within the C Programming forums, part of the General Programming Boards category; this thing seems to run twice? does anyone see why? I dont want the zeros at the end i use ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    12

    Double print

    this thing seems to run twice? does anyone see why? I dont want the zeros at the end

    i use the data file

    a e i o u A E I O U


    help!


    Code:
    ____________________my.h_________________________
    #include <stdio.h>
    #include <stdlib.h>
    
    typedef int CNT;
    typedef char DATA;
    typedef struct TAG
    {
            DATA data;
            struct TAG* link;
    }NODE;
    
    int main(void);
    void makelist(NODE*, NODE*);
    void displist(NODE*, NODE*);
    CNT vowel(NODE*);
    CNT xs(NODE*);
    void list(NODE*);
    
    ______________________main_____________________
    
    #include "my.h"
    
    int main(void)
    {
    
            NODE* List= NULL;
            NODE* Ulist = NULL;
            makelist ( List, Ulist);
            displist ( List, Ulist);
    
            return 0;
    }
    
    
    
    ____________________makelist_____________________
    
    #include "my.h"
    
    void makelist(NODE* a, NODE* b)
    {
    
            //local declarations
            NODE* now;
            DATA file;
    
            //statements
            while(1)
    
     {
                    scanf("%c", &file);
                    if(file == '\n')        break;
                    now = malloc(sizeof(NODE));
                    (*now).data = file;
                    (*now).link = a;
                    a = now;
    
    
            
                    if((file == 'A')|| (file == 'B')|| (file == 'C')|| (file
    == 'D')|| (file == 'E')||
                       (file == 'F')|| (file == 'G')|| (file == 'H')|| (file
    == 'I')|| (file == 'J')||
                       (file == 'K')|| (file == 'L')|| (file == 'M')|| (file
    == 'N')|| (file == 'O')||
                       (file == 'P')|| (file == 'Q')|| (file == 'R')|| (file
    == 'S')|| (file == 'T')||
                       (file == 'U')|| (file == 'V')|| (file == 'W')|| (file
    == 'X')|| (file == 'Y')||
                       (file == 'Z'))
                    {
    
            
                            now = malloc(sizeof(NODE));
                            (*now).data = file;
                            (*now).link = b;
                            b = now;
                    }
    
    }//while
    displist(a,b);
                       
            return;
    }
    
     ____________________________displist___________________
    
    
    #include "my.h"
    
    void displist(NODE* a, NODE* b)
    {
    
    printf("\n\n\n");
    list(a);
    printf("\n");
    list(b);
    printf("\n");
    printf("Total number of vowels: %3d\n", vowel(a));
    printf("Total number of Xs:     %3d\n", xs(b));
    printf("\n\n\n");
    
    return;
    }
    
    
    
    
    _________________vowel_______________
    
    
    #include "my.h"
    
    CNT vowel(NODE* a)
    {
    
            //local variables
            CNT vowels = 0;
            NODE* now = a;
    
            //statements
            while( now != NULL)
    {
                    if(((*now).data == 'a')|| ((*now).data == 'A')||
    ((*now).data == 'e')|| ((*now).data == 'E')||
                       ((*now).data == 'i')|| ((*now).data == 'I')||
    ((*now).data == 'o')|| ((*now).data == 'O')||
                       ((*now).data == 'u')|| ((*now).data == 'U'))
                            vowels++;
                    now = (*now).link;
    }
    
            return vowels;
    }
    
    
    
    _____________________xs.c_______________
    
    #include "my.h"
    
    CNT xs(NODE* a)
    
    {
    
            //local variables
            CNT Xs = 0;
            NODE* now = a;
    
            //statements
            while(now != NULL)
            {
                    if(((*now).data == 'X'))
                            Xs++;
                    now = (*now).link;
            }
    
            return Xs;
    }
    
    
    
    _______________list_______________
    
    #include "my.h"
    
    void list(NODE* a)
    {
    
            //locla variables
            NODE* now=a;
    
            //statements
            while(now != NULL)
            {
                    printf("%c",(*now).data);
                    now = (*now).link;
            }
    
            return;
    }
    output

    U O I E A u o i e a
    UOIEA
    Total number of vowels: 10
    Total number of Xs: 0








    Total number of vowels: 0
    Total number of Xs: 0

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Well, look at your function calls:
    main calls: makelist, displist
    makelist calls: displist
    Looks like displist gets called twice....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. Please HELP!!
    By traz in forum C++ Programming
    Replies: 4
    Last Post: 04-14-2003, 09:20 PM
  4. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM
  5. what's the difference?
    By iluvmyafboys in forum C++ Programming
    Replies: 13
    Last Post: 02-28-2002, 08:25 PM

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