character inputs and linked lists
hi, i really need help please.
this code is using scanf with linked lists and the problem im mainly having is that if the input is more than one word eg 'hello world', it doesnt input the two words inside the array. its supposed to be reading from standard input and the 1st letter of each node is printed out. and if its a vowel, it prints out a * after the letter. heres an example of input output.
input:
all
people are
able
to
breathe
output:
a*pa*tb
its skipping the whitespace. ive tried using getchar, but i dont know how to properly copy the characters individually into the array. i also want to keep the code as simple as possible.
Code:
#include<stdlib.h>
#include<stdio.h>
#include <string.h>
typedef struct Node {
char string;
struct Node * next;
}Node;
int main()
{
Node * curr, * head = NULL, * previous = NULL;
char line[100];
char *linep;
char ch;
while((scanf("%s", line)) != EOF)
{
linep = strdup(line);
curr = (Node *)malloc(sizeof(Node));
curr->string = linep[0];
if(head == NULL)
{
head = curr;
previous = curr;
}
else
previous->next = curr;
previous = curr;
}
curr = head;
while(curr)
{
ch = curr->string;
printf("%c", ch);
if(ch == 'a' || ch == 'A')
printf("*");
if(ch == 'e' || ch == 'E')
printf("*");
if(ch == 'i' || ch == 'I')
printf("*");
if(ch == 'o' || ch == 'O')
printf("*");
if(ch == 'u' || ch == 'U')
printf("*");
curr = curr->next;
}
return(0);
}
cheers