Hi all,
I'm writing a piece of code for one of my classes which is supposed to take in a string from the user. It will store the string into an array and then it has to copy the array elements into a linked list. I then have to print each chars from the linked list that's not a vowel. I was going to just use a conditional if statement for this part but my issue is I don't know how to implement the code to go back to the first node and then cycle forward through them to reprint the chars. My code only prints me the char in the last node. Any pointers (pun?) lol
Also, I get this warning:
Undeclared function 'gets'; assuming 'extern' returning 'int'.
relating to my use of gets(xxx); but I can't figure out how to fix the warning so any ideas?
My code thus far below:
Thanks all!
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define maxsize 500
struct node
{
char data;
struct node *next;
};
int main (void)
{
int nodenum=0;
char sentence[maxsize];
struct node* head = NULL;
struct node* temp;
head=(struct node*)malloc(sizeof(struct node));
temp=head;
temp->next=NULL;
printf("Enter string\n");
gets(sentence);
while(head->next!=NULL)
{
head=head->next;
}
do /*puts each char in the array into a node of the linked list*/
{
head->next=(struct node*)malloc(sizeof(struct node));
head=head->next;
head->data = sentence[nodenum];
temp=head;
head->next = NULL;
nodenum++;
}
while(sentence[nodenum]!='\0');
do
{
printf("\n%c",temp->data); /*This only prints the last letter in the linked list. How to manipulate to go back through the nodes to print corresponding char into a string?*/
}
while(head==NULL);
free(head);
free(head->next);
free(temp);
getchar();
getchar();
return(0);
}