In C language, In this project you are to create your own program, which has at
ID: 3717549 • Letter: I
Question
In C language,
In this project you are to create your own program, which has at least SIX of the following functions listed below..
1) 2D Arrays
2) File I/O
3) Strings
4) Pass by Reference
5) Structures
6) Command Line Arguments
7) Sorting
8) Recursion
9) Stack/Queue
10) Header Files
11) Linked Lists —*Pointers*
Proper use of each of the six functions is worth five points each.
Requirements—— This program shouldn’t be a straightforward implementation of the 6 functions used, but rather a somewhat useful, semi real-world program. Creativeness and originality of the program is included in the grade which is worth 5 points.
Proper documentation is also graded which includes comments throughout the code listing the functions used and documentation for how to use the program.
Six topics x 5 points ———— 30 points
Documentation ———— 5 points
Creativeness/Originality ——— 5 points
Explanation / Answer
Source code:-
----------------------
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Student_linkedlist
{
char fName[100];
char lName[100];
int age;
struct Student_linkedlist * next; //Self Referential Structure
}; //Structures
struct Student_linkedlist *first=NULL,*last=NULL,*swapping;
struct Student_linkedlist *head;
void insert_linkedlist(char input[][80],int length)
{
char firstName[100];
char LastName[100];
int Age;
int i;
struct Student_linkedlist *temp;
for(i=0;i<length;i++)
{
temp=(struct Student_linkedlist*)malloc(sizeof(struct Student_linkedlist));
//Linked List Pointers
sscanf(input[i],"%s %s %d",firstName,LastName,Age);
strcpy(head->fName,firstName); //String Copy
strcpy(head->lName,LastName);
head->age=Age;
if(head== NULL)
{
head=temp;
head->next=NULL;
}
else
{
temp->next=head;
head=temp;
}
}
}
void PrintData(struct Student_linkedlist *head)
{
struct Student_linkedlist *temp;
temp=head;
if(temp!=NULL)
{
printf("%s %s %d",temp->fName,temp->lName,temp->age);
PrintData(temp->next); //Recursion to Print the Data
}
}
int main() //Command Line Arguements
{
char line[6][80]; //Two Dimentional Array to store file records.
int i=0,count=0;
FILE *file = fopen("FileInput.txt", "r"); //File Input/Outputs
while(fgets(line[i],sizeof(line), file)!=NULL)
{
printf("%s ",line[i]);
line[i][strlen(line[i])-1]='';
i++;
count++;
}
fclose(file);
insert_linkedlist(line,count);//Pass byReference.
PrintData(head);
return 0;
}
Inputfile:-
----------------------
venkana kodada 25
prudhvi kumar 24
Santhan Prem 23
Narayna Chea 25
Sample Output:-
--------------------
venkana kodada 25
prudhvi kumar 24
Santhan Prem 23
Narayna Chea 25
venkana kodada 25
--------------------------------
Process exited after 29.88 seconds with return value 3221225477
Press any key to continue . . .