C

Actively programming today 5/17/2016.   ( Not happy  PPLUG (Pikes Peak Linux Users Group – is not active, and I’m a SATLUG member from San Antonio, Texas. I was hoping to find an active Linux group here in Colorado Springs. 

PROGRAMMING AND COMPLETING A LINKED LIST … ugh brain went foggy as I was coding this on the fly (Learning as I went).

This is a video of me compiling, and dissasembling C code in Linux. Using GCC compiler. As I read and follow along the book titled:

“Hacking the art of exploitation”.
I enjoy C programming in windows\Linux and Bash Shell in Linux.
I got side tracked, but I’ll dive back in, and continue the series of videos, and explaining what’s going on in case someone else reading the book is confused on what they’re learning. Or is trying to learn assembler codes and understand their dissembler in Linux.

I am also joined to various C, C++ , and C# facebook programming groups . I am also working daily on completing Bob Tabor’s LearnVisualStudio.net  paid-for course. To learn ASP.net front-end, and SQL-back end programming and communication in my pursuit and passion of some day becoming a software engineer.  I will add video’s later of actively programming dynamic linked list as below to help others understand it.  YES I am will create a GitHub account, and share code projects there, but I haven’t gotten around to it yet.

Once I finish the Search, and Delete query functions to enumerate the list with; I’ll update the code here, and make a video to help others understand C Linked List programming. Recently,  Bjarne BStroup said to avoid linked list but I find them elementary to understanding memory node programming and Data structures being a novice programmer.

 

/// My  C   programming,  completed linked list with add, remove, search, and display functions.

‪#‎include‬ <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

struct node
{
int data;
int nodenum;
char empname[15];
struct node* next;
};
int CreateList(struct node* head);
int DisplayList(struct node* traverse);
int DeleteNode(struct node* nodekiller);
int AddNode(struct node* addnode);
int Search(struct node* seekit);
int main()
{
struct node* nodeptr = (struct node*)malloc(sizeof(struct node));
int menu;
restart:
printf(“\tTo create a list enter the number 1\n”);
printf(“\tTo display a previously created list enter the number 2\n”);
printf(“\tTo delete an entry enter 4\n”);
printf(“\tTo Add an entry into a list enter 5\n”);
printf(“\tTo Search for an employee name enter 6\n”);
printf(“\tTo exit program enter 3\n”);
printf(“Enter choice: “);
scanf(“%d”,&menu);
switch(menu)
{
case 1:
nodeptr = CreateList(nodeptr);
break;
case 2:
DisplayList(nodeptr);
break;
case 3:
return 0;
break;
case 4:
DeleteNode(nodeptr);
break;
case 5:
AddNode(nodeptr);
break;
case 6:
Search(nodeptr);
break;
default:
printf(“\nYou did not enter the correct choice try again\n”);
system(“pause”);
goto restart;
}
goto restart;

return 0;
}
int CreateList(struct node* head)
{
int choice;
int i;

struct node* firstNode = (struct node*)malloc(sizeof(struct node));
struct node* seeker = (struct node*)malloc(sizeof(struct node));
printf(“\t Please enter a number of employee’s to input into a list\n”);
printf(“\t Enter number here: “);
scanf(“%d”,&choice);
seeker = firstNode;
for(i = 1; i <= choice; i++)
{
seeker->nodenum = i;
printf(“\n Enter employee #%d, name: “,i);
scanf(“%s”,&seeker->empname);
printf(“\n Enter Badge #; “);
scanf(“%d”,&seeker->data);
seeker->next = (struct node*)malloc((sizeof(struct node)));
seeker = seeker->next;
}
seeker->data = 99999;
system(“cls”);
return firstNode;
}
int DisplayList(struct node* traverse)
{
system(“cls”);
while(traverse->data != 99999)
{
if(traverse->data == 0)
{
printf(“\nEmpty List please use option one to create a list\n”);
break;
}
printf(“Employee Name: %s Badge#: %d \n”,traverse->empname,traverse->data);
traverse = traverse->next;

}
return 0;
}
int DeleteNode(struct node* nodekiller)
{
bool Done = false;
printf(“\tPlease enter the name of a terminated\n\temployee to remove from the list\n”);
printf(“Enter Name: “);
char name[15];
scanf(“%s”,&name);
while(Done == false)
{

if(nodekiller->next->data == 99999)
{
nodekiller->data = 0;
strcpy(nodekiller->empname,”Error”);
break;
}

if(strcmp(nodekiller->next->empname,name) == 0)
{
struct node* temp = (struct node*)malloc(sizeof(struct node));
temp = nodekiller->next;
nodekiller->next = nodekiller->next->next;
free(temp);
temp = NULL;
Done = true;
}

nodekiller = nodekiller->next;
}
return 0;
}
int AddNode(struct node* addnode)
{
bool Done = false;
while(Done == false)
{
if(addnode->next->data == 99999)
{
struct node* tempnode = (struct node*)malloc(sizeof(struct node));
tempnode->next = addnode->next;
addnode->next = tempnode;
printf(“Enter Employee’s Name:”);
scanf(“%s”,&tempnode->empname);
printf(“\nEnter Badge#:”);
scanf(“%s”,&tempnode->data);
Done = true;
break;
}
addnode = addnode->next;
}
}
int Search(struct node* seekit)
{
printf(“Please enter an Employee name to Search for\n”);
printf(“Enter it here: “);
char findname[15];
scanf(“%s”,&findname);
while(seekit->data != 99999)
{
if(strcmp(seekit->empname,findname) == 0)
printf(“\nFOUND: Employee: %s, Badge#: %d\n\n”,seekit->empname,seekit->data);

seekit = seekit->next;
}
return 0;
}