Hello guys, I made program using with c. And i found compiling is not successful because small error. Please see full coding work below and error is highlighted in colour. Please help me to fix this code as i have to give this Assignment today. Do something. Thanking you
Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define STR_SIZE 100
struct node
{
char data;
struct node *next;
};
void start(void);
void getString(void);
void makeLinkList(struct node *head);
void printInPutStr(struct node *head);
void getNumber(void);
void replaceNode(num inPut, struct node *head);
void printOutPutStr(struct node *head);
void printStr(struct node *head);
void end(void);
void emptyLinkedList(struct node *head);
char inPutStr[STR_SIZE];
num number;
int main(void)
{
char inPutChar; // USED AS PART OF PROGRAM TERMINATION
num inPut; // HOLDS VALUE OF INDEX ENTERED BY THE USER
struct node *head = NULL; // SAME
int count; // INDEX VALUE
printf("\n Advanced Assignment - Data Flow Structures & Linked Lists (V1.01)");
printf("\n -----------------------------------------------------------------\n\n");
printf(" USER INSTRUCTIONS \n");
printf(" > Write a program that creates a linked list of characters from a string \n");
printf(" > entered by the user.\n");
printf(" > The program is then to accept a second string and an index from the user. \n");
printf(" > The second string is then to be inserted into the first string at the \n");
printf(" > location given by the index. \n\n");
start();
getString();
head = (struct node*) calloc(1, sizeof (struct node));
makeLinkList(head);
printInPutStr(head);
inPut = getNumber();
replaceNode(inPut, head);
printOutPutStr(head);
end();
}
void start(void)
{
printf(" STARTING PROGRAM...\n");
}
void getString(void)
{
printf(" Please enter a string (Maximum length %d characters) \n\t C:\> ", STR_SIZE);
gets(inPutStr);
fflush(stdin);
while(inPutStr[0] == 0 || inPutStr[0] == ' ')
{
printf("\n\t NOTHING INSERTED! RE-ENTER A STRING \n\t C:\> ");
gets(inPutStr);
fflush(stdin);
}
}
void makeLinkList(struct node *head)
{
struct node *current, *previous;
int i;
current = head;
current->next = (struct node*)calloc(1, sizeof(struct node));
current=current->next;
for ( i = 0 ; inPutStr[i] != 0 ; ++i )
{
current->data= inPutStr[i];
current->next = (struct node*)calloc(1, sizeof(struct node));
previous = current;
current = current->next;
}
free(current);
previous->next = NULL;
current = head;
}
void printInPutStr(struct node *head)
{
printf("\n USER INPUT:\n > ");
emptyLinkedList(head);
printStr(head);
}
num getNumber(void)
{
int inP1, inP2;
printf("\n\n Enter Index value \n\t C:\> ", STR_SIZE);
scanf("%d",&number.inP1);
fflush(stdin);
while(number.inP1<1)
{
printf("\n\t INVALID ENTRY! RE-ENTER DIGIT \n\t C:\> ");
scanf("%d",&number.inP1);
fflush(stdin);
}
return (number);
}
void replaceNode(num inPut, struct node *head)
{
struct node *current, *previous, *forward;
int i=0,j=0;
int l,c;
l=number.inP1;
current = head;
for( ; j<l; j++)
{
current=current->next;
}
while (current!=NULL)
{
inPutStr[i]=current->data;
current=current->next;
i++;
}
current = head;
j=0;
while(j<=l+1)
{
inPutStr[i]=current->data;
current=current->next;
i++;
j++;
}
current = head;
i=0;
while(current!=NULL)
{
current->data = inPutStr[i];
i++;
current = current->next;
}
}
void printOutPutStr(struct node *head)
{
printf("\n MODIFIED STRING:\n > ");
emptyLinkedList(head);
printStr(head);
}
void printStr(struct node *head)
{
struct node *current;
current = head;
do
{
current = current->next;
printf("%c", current->data);
}
while(current->next != NULL);
}
void end(void)
{
char inPutChar;
printf(" PRESS ANY KEY TO EXIT PROGRAM...\n");
scanf("%c",&inPutChar);
fflush(stdin);
}
void emptyLinkedList(struct node *head)
{
if(head->next == NULL)
{
printf("\tEmpty Linked List!!!!");
}
}