-
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
-
Well, look at your function calls:
main calls: makelist, displist
makelist calls: displist
Looks like displist gets called twice....