I have created master array. But the main problem to create master array by pointer.
Let see how it is done.
I have created master array. But the main problem to create master array by pointer.
Let see how it is done.
reading file from file discriptor.
creating buffer to store characters from text file.
sorting unique chaacters and saving them into master array.
you should take care of your Pd that it should be unmounted before you did the for mating.
use the following commands on terminal
mkfs.vfat /dev/sdb1
sdb1 is you node name(that can be check through ‘dmesg’ or ‘fdisk -l’)
you can also change the your pd name by using following command on terminal
mkfs.vfat -n ‘desired pd name’ /dev/sdb1
RCS file: delete_M_nodes_after_N.c,v
Working file: delete_M_nodes_after_N.c
head: 1.9
branch:
locks: strict
root: 1.9
access list:
symbolic names:
keyword substitution: kv
total revisions: 9; selected revisions: 9
description:
Code to demonstrate how to delete M nodes after N nodes in a single linked list in C language.
—————————-
revision 1.9 locked by: root;
date: 2014/02/20 01:52:28; author: root; state: Exp; lines: +7 -1
Logical error fixed.
After deleting a node by freeing a memory using free(),the pointer is not initialized to NULL.
Status:After N nodes M nodes get deleted successfully.The program is working absolutely correctly.To check after deleting N nodes display_function is used to print the remaining nodes of the linked list.
—————————-
revision 1.8
date: 2014/02/20 01:35:38; author: root; state: Exp; lines: +1 -1
After compilation,an error occurs due to pointer to a structure of type struct node is not declared.
Bug fixed.
—————————-
revision 1.7
date: 2014/02/20 01:32:15; author: root; state: Exp; lines: +35 -2
delete_nodes() function is implemented.Prototype of the function is declared.The function takes 3 arguments:
1.How many nodes to delete.
2.After how many nodes to delete.
3.start node of the linked list.
Checking…………….
—————————-
revision 1.6
date: 2014/02/20 00:37:24; author: root; state: Exp; lines: +11 -0
Prototype of the display_nodes() function is declared.The body of the display_nodes() function is imlemented.
Checking……..
—————————-
revision 1.5
date: 2014/02/20 00:17:08; author: root; state: Exp; lines: +26 -0
insert_node() function is implemented to insert a node at the end of the linked list.
—————————-
revision 1.4
date: 2014/02/20 00:03:45; author: root; state: Exp; lines: +33 -2
create_linked_list() function is implemented to create the linked list.A flag variable is used to ensure that the linked list is created just once.If the user chooses the create a linked list option next time,a message will get displayed telling the user that the linked list is already created.
—————————-
revision 1.3
date: 2014/02/19 23:47:59; author: root; state: Exp; lines: +18 -0
Header file:<stdlib.h> is included to support exit() function.exit() function is used to help the user come out of the program.
—————————-
revision 1.2
date: 2014/02/19 23:44:17; author: root; state: Exp; lines: +12 -1
A layout is prepared for the user.The main menu is displayed to the user each time untill the user chooses to exit the program.
—————————-
revision 1.1
date: 2014/02/19 23:39:52; author: root; state: Exp;
Initial revision
=============================================================================
RCS file: display_linked_list.c,v
Working file: display_linked_list.c
head: 1.10
branch:
locks: strict
root: 1.10
access list:
symbolic names:
keyword substitution: kv
total revisions: 10; selected revisions: 10
description:
Code to demonstrate how to display a linked list using recursion in C language.
—————————-
revision 1.10 locked by: root;
date: 2014/02/19 23:31:53; author: root; state: Exp; lines: +18 -6
display_nodes() function is implemented successfully.The recursive calls are made in the program because the display_function calls itself again and again.
The base condition is also added to stop the recursive calls.
Status:The linked list is displayed correctly using recursion in the forward order.
—————————-
revision 1.9
date: 2014/02/19 23:20:32; author: root; state: Exp; lines: +27 -1
create_node() function is implemented that inserts a node at the end of the linked list.
—————————-
revision 1.8
date: 2014/02/19 14:17:07; author: root; state: Exp; lines: +12 -0
Implemented the body of the create_linked_list function.
Checking….
—————————-
revision 1.7
date: 2014/02/19 14:11:53; author: root; state: Exp; lines: +1 -0
Prototype of the create_linked_list() function is declared.
Implementing the body of this function…….
—————————-
revision 1.6
date: 2014/02/19 14:09:46; author: root; state: Exp; lines: +19 -1
create_linked_list() function is called that creates the start node of the linked list.A flag variable is used to check if the linked list is created already or not.
—————————-
revision 1.5
date: 2014/02/19 14:01:06; author: root; state: Exp; lines: +2 -0
Declared two structure variables of type struct node and are initialized to NULL.
—————————-
revision 1.4
date: 2014/02/19 13:59:13; author: root; state: Exp; lines: +5 -0
A structure is declared of type node,consisting of two data members.One is the info part and the other is the pointer to a structure of type struct node.
—————————-
revision 1.3
date: 2014/02/19 13:57:26; author: root; state: Exp; lines: +15 -0
Header file:<stdlib.h> is included to support exit() function.It is used to end the program in case the user wants to end it.
—————————-
revision 1.2
date: 2014/02/19 13:53:24; author: root; state: Exp; lines: +10 -0
A layout is prepared which displays the main menu to the user so that the user can enter a choice.
—————————-
revision 1.1
date: 2014/02/19 13:40:34; author: root; state: Exp;
Initial revision
=============================================================================
RCS file: header.h,v
Working file: header.h
head: 1.4
branch:
locks: strict
root: 1.4
access list:
symbolic names:
keyword substitution: kv
total revisions: 4; selected revisions: 4
description:
Header file:<linux/init.h> is included to support module_init() and module_exit() macros.
—————————-
revision 1.4 locked by: root;
date: 2014/02/18 16:10:55; author: root; state: Exp; lines: +1 -0
Header file:<moduleparam.h> is included to support module_param() macro.
—————————-
revision 1.3
date: 2014/02/18 15:51:35; author: root; state: Exp; lines: +4 -0
A macro called DEBUG is defined using #define.
—————————-
revision 1.2
date: 2014/02/18 15:49:52; author: root; state: Exp; lines: +4 -0
Header file:<linux/module.h> is included to support MODULE_LICENSE and MODULE_AUTHOR macros.
—————————-
revision 1.1
date: 2014/02/18 15:33:03; author: root; state: Exp;
Initial revision
=============================================================================
RCS file: cleanup.c,v
Working file: cleanup.c
head: 1.2
branch:
locks: strict
root: 1.2
access list:
symbolic names:
keyword substitution: kv
total revisions: 2; selected revisions: 2
description:
Code that will run when the module is removed using the rmmod.
—————————-
revision 1.2 locked by: root;
date: 2014/02/18 16:04:27; author: root; state: Exp; lines: +12 -0
Two debug statements are added inside the cleanup function that indicates the start and end of the cleanup function.
—————————-
revision 1.1
date: 2014/02/18 15:28:40; author: root; state: Exp;
Initial revision
=============================================================================
RCS file: initial.c,v
Working file: initial.c
head: 1.3
branch:
locks: strict
root: 1.3
access list:
symbolic names:
keyword substitution: kv
total revisions: 3; selected revisions: 3
description:
Code to demonstrate how parameters can be passed to a module while loading it using insmod by a macro called module_param defined in moduleparam.h.
—————————-
revision 1.3 locked by: root;
date: 2014/02/18 16:17:36; author: root; state: Exp; lines: +5 -2
Included module_param() macro that takes three arguments:name of the variable,its type and permission mask.
Checking…..
—————————-
revision 1.2
date: 2014/02/18 15:54:52; author: root; state: Exp; lines: +20 -0
Two statements that indicates the start and end of the initialization function are added.
—————————-
revision 1.1
date: 2014/02/18 15:24:36; author: root; state: Exp;
Initial revision
=============================================================================
i have installed fedora 17 but my pc heats up too much.I have tried all things.And one more thing brighness key dont work also.
RCS file: delete_n_nodes.c,v
Working file: delete_n_nodes.c
head: 1.11
branch:
locks: strict
root: 1.11
access list:
symbolic names:
keyword substitution: kv
total revisions: 11; selected revisions: 11
description:
Code to demonstrate how to delete a node at specified position and also how to delete all the nodes in the single linked list.
—————————-
revision 1.11 locked by: root;
date: 2014/02/18 02:32:59; author: root; state: Exp; lines: +16 -6
Logical error fixed.
Issue:double pointer is not used to point to the start node.With the help of this double pointer each node is deleted starting from the start node.
There is a slight modification inside the display function needs to be done because if there is no linked list.The display function must include a check to display an a message to the user that there is no linked list which can be displayed.
Status:delete_all_nodes() function is implemented successfully with delete_node_at_n() position.
—————————-
revision 1.10
date: 2014/02/18 02:24:11; author: root; state: Exp; lines: +1 -0
Prototype of the delete_all_nodes() is declared.
Logical error fixed.
—————————-
revision 1.9
date: 2014/02/18 02:22:09; author: root; state: Exp; lines: +12 -0
A function to delete all the nodes in the single linked list in C is implemented.
Previously the function delete_node_at_n() is implemented and it is working correctly.
—————————-
revision 1.8
date: 2014/02/18 02:14:45; author: root; state: Exp; lines: +25 -2
delete_node_at_n() function is implemented.The dynamically allocated memory is freed using free() function call.
Checking……
—————————-
revision 1.7
date: 2014/02/17 16:51:39; author: root; state: Exp; lines: +2 -1
Logical error fixed.
Issue:The address of the newly created node is node returned to the main function.
—————————-
revision 1.6
date: 2014/02/17 16:49:36; author: root; state: Exp; lines: +2 -2
Logical error fixed.
Issue:start is used instead of temp inside the create_list() and create_node() functions.
—————————-
revision 1.5
date: 2014/02/17 16:48:03; author: root; state: Exp; lines: +11 -0
display_node() function is implemented.
Checking……
—————————-
revision 1.4
date: 2014/02/17 16:41:31; author: root; state: Exp; lines: +32 -0
create_node() function is implemented that inserts a node at the end of a single linked list.
Now defining the display_nodes() function to display the nodes in the linked list.
—————————-
revision 1.3
date: 2014/02/17 16:30:19; author: root; state: Exp; lines: +27 -1
A structure is defined with 2 members:info and pointer to a structure of type struct node.
create_list() function prototype is declared to create the linked list.On error a message will get displayed.
—————————-
revision 1.2
date: 2014/02/17 16:24:22; author: root; state: Exp; lines: +18 -0
Header file:<stdlib.h> is included to support exit() function.
—————————-
revision 1.1
date: 2014/02/17 16:22:33; author: root; state: Exp;
Initial revision
=============================================================================
#include
#include
#include
#include
#include
#include
#include
#include
#include
MODULE_LICENSE(“GPL”);
MODULE_AUTHOR(“KERNEL_CODE”);
#define DEBUG
#define NAME “char_dev”
#define NODE 5
#define SCULL_MAJOR 0
#define SCULL_MINOR 0
#define QUANTUM 8
#define SIZE 0
#define QSET 8
#define DEV_SIZE 1024
#define DEVICE_NAME “char_dev”
#define CLASS_NAME “scull”
static int scull_minor = SCULL_MINOR;
static int scull_major = SCULL_MAJOR;
static struct class* scull_class = NULL;
static struct device* scull_device = NULL;
int size = SIZE;
int qset = QSET;
int quantum = QUANTUM;
struct Scull_qset{
struct Scull_qset *next;
void **data1;
};
dev_t dev;
struct Scull_dev{
struct Scull_qset *data;
int quantum;
int qset;
int device_size;
int data_size;
struct cdev cdev;
};
struct Scull_dev *scull_dev;
const struct file_operations fops=
{};
struct inode *finode;
struct file *ffile;
/***********************************************************************************/
/* sysfs entry for 1st operation *//*we can pass the arguments we need*/
static ssize_t sys_entry1(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
{
#ifdef DEBUG
printk(KERN_INFO ” string from user is%s\n”,buf);
#endif
return count;
}
/* Declare the sysfs entries. The macros create instances of dev_attr_fifo and dev_attr_reset */
static DEVICE_ATTR(entry, S_IWUSR, NULL, sys_entry1);
/***********************************************************************************/
static int __init hello_world(void){
int retval;
retval = alloc_chrdev_region(&dev,scull_minor,NODE,DEVICE_NAME);
scull_minor = MINOR(dev);
scull_major = MAJOR(dev);
scull_dev = kmalloc(NODE*sizeof(struct Scull_dev),GFP_KERNEL);
memset(scull_dev,”,sizeof(struct Scull_dev));
/* use a “virtual” device class. */
scull_class = class_create(THIS_MODULE, CLASS_NAME);
printk(KERN_DEBUG”register device class ‘%s’\n”, CLASS_NAME);
if (!scull_class) {
printk(KERN_DEBUG”register device class ‘%s’\n”, CLASS_NAME);
goto OUT;
}
/* With a class, the easiest way to instantiate a device is to call device_create() */
scull_device = device_create(scull_class, NULL, MKDEV(scull_major, 0), NULL, CLASS_NAME “_” DEVICE_NAME);
if (!scull_device) {
printk(KERN_DEBUG”register device class ‘%s’\n”, DEVICE_NAME);
goto OUT;
}
/* dev_attr_entry come from the DEVICE_ATTR(…) earlier */
retval = device_create_file(scull_device, &dev_attr_entry);
if (retval cdev,&fops);
scull_dev->quantum = quantum;
scull_dev->qset = qset;
scull_dev->device_size= size;
scull_dev->cdev.owner = THIS_MODULE;
scull_dev->cdev.ops = &fops;
retval = cdev_add(&scull_dev->cdev,dev, NODE);
if(retvalcdev);
kfree(scull_dev);
device_remove_file(scull_device, &dev_attr_entry);
device_destroy(scull_class, MKDEV(scull_major, 0));
class_unregister(scull_class);
class_destroy(scull_class);
#ifdef DEBUG
printk(KERN_INFO”cha_device unregistration from fun %s\n”,__func__);
printk(KERN_INFO”BYE BYE \n”);
#endif
}
module_init(hello_world);
module_exit(hello_exit);
RCS file: x.c,v
Working file: x.c
raghav: 1.5
access list:
keyword substitution: kv
total revisions: 5; selected revisions: 5
description:
Program to delete any file using file handling in c
With function remove() we can delete/remove any file from the file system . remove function takes argument as path of the file . and on success it returns 0.
—————————-
revision 1.5 locked by: raghav;
date: 2014/02/16 13:50:15; author: raghav; state: Exp; lines: +1 -0
remove function returns 0 on sucess .
—————————-
revision 1.4
date: 2014/02/16 13:48:28; author: raghav; state: Exp; lines: +1 -1
use of remove function to remove the file by writing the path of the file which we want to delete
—————————-
revision 1.3
date: 2014/02/16 13:47:46; author: raghav; state: Exp; lines: +1 -1
input the name of file which we want to delete using gets function
—————————-
revision 1.2
date: 2014/02/16 13:46:43; author: raghav; state: Exp; lines: +1 -1
*** empty log message ***
—————————-
revision 1.1
date: 2014/02/16 13:46:14; author: raghav; state: Exp;
Initial revision
=============================================================================
There are few steps to follow to open a file inside kernel from application layer.
1. Insert your character device driver inside the kernel using insmod and check its entry in the device driver table using cat /proc/devices and note down its major minor number.
2. Now make a node using mknod following with node name character and major minor number example : mknod nod c 250 0
3. Next step is to run a file (application.c) in the application layer and through the help of node open the file inside the kernel : fd=open(“nod”,O_RDWR);
include this statement in the file (application.c) which is in the application layer
4. After executing the application.c file which is in the application layer. check the fd returned by open function. If it is positive, that means file is opened successfully.
5.Last step to unlink the node using unlink node and remove the driver using rmmod
/////////////////////////////////////////////////////////////////////////////
RCS file: clean.c,v
Working file: open.c
head: 1.5
branch:
locks: strict
raghav: 1.5
access list:
symbolic names:
keyword substitution: kv
total revisions: 5; selected revisions: 5
description:
Creating a node between user and kernerl level using mknod following with node name and c for character device driver and combination of major minor no.
—————————-
revision 1.5 locked by: raghav;
date: 2014/02/13 11:20:48; author: raghav; state: Exp; lines: +2 -0
creating a file in application layer and now this file will open the file inside the kernel level using node
we can check it: whether its working or not by printing the fd returned from open func. if its negative then operation unsuccessful.
—————————-
revision 1.4
date: 2014/02/13 10:19:28; author: raghav; state: Exp; lines: +1 -1
Error detected: defination of scull_open function whose arguments are struct i node and struct file
—————————-
revision 1.3
date: 2014/02/13 10:18:05; author: raghav; state: Exp; lines: +6 -5
Including the open.o in the Make file.
—————————-
revision 1.2
date: 2014/02/13 06:09:06; author: raghav; state: Exp; lines: +3 -5
included the struct file_operation Scull_ops.
—————————-
revision 1.1
date: 2014/02/13 05:58:43; author: raghav; state: Exp;
Initial revision
=============================================================================
RCS file: remove_duplicate_sort.c,v
Working file: remove_duplicate_sort.c
head: 1.9
branch:
locks: strict
root: 1.9
access list:
symbolic names:
keyword substitution: kv
total revisions: 9; selected revisions: 9
description:
Code to demonstrate how to remove duplicates in a sorted linked list.
—————————-
revision 1.9 locked by: root;
date: 2014/02/16 18:47:38; author: root; state: Exp; lines: +6 -0
Bug fixed.
Issue:After freeing the memory the pointer is not set to NULL,because of which is it is becoming a dangling pointer i.e a pointer that is not pointing to valid memory location.
Status:The program is working absolutely fine i.e it is removing all the duplicates present in the single linked list.
—————————-
revision 1.8
date: 2014/02/16 18:34:46; author: root; state: Exp; lines: +1 -0
Segmentation fault is coming due to illegal access of memory.
Debugging….
—————————-
revision 1.7
date: 2014/02/16 18:30:12; author: root; state: Exp; lines: +1 -2
New line character(\n) is added to make the output of display more readable.
Inside remove_duplicates() function break statement is removed to check the removal of duplicate elements.
—————————-
revision 1.6
date: 2014/02/16 18:25:03; author: root; state: Exp; lines: +23 -0
Logical error fixed.
Issue:The pointer to structure of type struct node is updated before the start pointer is updated.
Extending this code to remove all the duplicates in the linked list.
—————————-
revision 1.5
date: 2014/02/16 17:13:11; author: root; state: Exp; lines: +11 -0
display_nodes() function prototype is given and its functionality is given.
—————————-
revision 1.4
date: 2014/02/16 17:00:00; author: root; state: Exp; lines: +29 -1
Body of the create_node(),create_linked_list() and insert_value() function is added in the code.
Code working correctly……
—————————-
revision 1.3
date: 2014/02/16 16:49:09; author: root; state: Exp; lines: +30 -1
Prototypes of the create_node() and create_linked_list() functions are declared.
Implementing the definitions of these functions…..
—————————-
revision 1.2
date: 2014/02/16 16:10:33; author: root; state: Exp; lines: +17 -0
Header file:<stdlib.h> is included to support exit() function.
A complete layout is prepared telling the user what are the available options.
—————————-
revision 1.1
date: 2014/02/16 16:08:48; author: root; state: Exp;
Initial revision
=============================================================================
RCS file: compare_linked_list.c,v
Working file: compare_linked_list.c
head: 1.9
branch:
locks: strict
root: 1.9
access list:
symbolic names:
keyword substitution: kv
total revisions: 9; selected revisions: 9
description:
Code to demonstrate how to compare the two single linked lists in C.
—————————-
revision 1.9 locked by: root;
date: 2014/02/16 15:35:35; author: root; state: Exp; lines: +5 -1
Status : Program to compare two single linked lists is implemented.
Previously the program was not working because the global variable was updating with number of times display function is called.Bug fixed.
—————————-
revision 1.8
date: 2014/02/16 14:59:51; author: root; state: Exp; lines: +41 -2
compare_two_lists() function is implemented to compare the two created linked lists.
Checking…………
—————————-
revision 1.7
date: 2014/02/16 14:32:32; author: root; state: Exp; lines: +2 -1
logical error fixed.
Issue:flag variable is declared of type struct node instead of int.
—————————-
revision 1.6
date: 2014/02/16 14:29:59; author: root; state: Exp; lines: +17 -0
Functions to display both the linked list are implemented.
Checking….
—————————-
revision 1.5
date: 2014/02/16 14:24:03; author: root; state: Exp; lines: +6 -2
Prototypes of the display functions are declared.
—————————-
revision 1.4
date: 2014/02/16 14:18:43; author: root; state: Exp; lines: +33 -2
create_list1() and create_list2() functions are implemented.
Developing the display functions.
—————————-
revision 1.3
date: 2014/02/16 00:54:39; author: root; state: Exp; lines: +64 -11
Inside the program create_node() function is implemented to create a node.
—————————-
revision 1.2
date: 2014/02/16 00:31:44; author: root; state: Exp; lines: +30 -0
Header file:<stdlib.h> is included to support exit() function.
—————————-
revision 1.1
date: 2014/02/16 00:27:09; author: root; state: Exp;
Initial revision
=============================================================================
RCS file: insert_at_n_pos.c,v
Working file: insert_at_n_pos.c
head: 1.12
branch:
locks: strict
root: 1.12
access list:
symbolic names:
keyword substitution: kv
total revisions: 12; selected revisions: 12
description:
Developing a general code that inserts a node at the N-position specified by the user in a single linked list.
—————————-
revision 1.12 locked by: root;
date: 2014/02/15 23:56:48; author: root; state: Exp; lines: +19 -2
Status:The node is getting inserted at the correct poistion as desired.
Program is working absolutely fine.
—————————-
revision 1.11
date: 2014/02/15 23:35:44; author: root; state: Exp; lines: +4 -4
Prototype of the insert_at_n_position() function is changed.
—————————-
revision 1.10
date: 2014/02/15 23:33:19; author: root; state: Exp; lines: +9 -1
Prototype of the insert_at_n_position() is declared.
Defining the body of the insert_at_n_position().
—————————-
revision 1.9
date: 2014/02/15 23:29:22; author: root; state: Exp; lines: +1 -1
\n(New line) character is added inside display_nodes function.
—————————-
revision 1.8
date: 2014/02/15 04:01:22; author: root; state: Exp; lines: +13 -1
A logical error ocurred because of which the linked list cannot be displayed.
Bug fixed.
—————————-
revision 1.7
date: 2014/02/15 03:47:07; author: root; state: Exp; lines: +12 -0
Function to display the nodes in the linked list is implemented.
—————————-
revision 1.6
date: 2014/02/15 03:41:57; author: root; state: Exp; lines: +20 -0
Function to insert a node at the end of the linked list is implemented.
The prototype of this function is also declared.
—————————-
revision 1.5
date: 2014/02/15 03:37:33; author: root; state: Exp; lines: +9 -1
Body of the create_list() function is defined.
Checking….
—————————-
revision 1.4
date: 2014/02/15 03:33:39; author: root; state: Exp; lines: +15 -1
Prototype of the create_list() is declared.
Inside the main() function it is called to create a linked list.
—————————-
revision 1.3
date: 2014/02/15 03:27:55; author: root; state: Exp; lines: +25 -0
exit() function is included to end the program.
Header file:<stdlib.h> is included to support the exit() function.
—————————-
revision 1.2
date: 2014/02/15 03:23:15; author: root; state: Exp; lines: +10 -0
A layout is prepared for the user asking him/her to perform a specific operation.
—————————-
revision 1.1
date: 2014/02/15 03:16:31; author: root; state: Exp;
Initial revision
=============================================================================
Q1. Can we print any cotent in the scanf statement (like, as “Datais”,) is tried to printed in the following program. If no then why not, if yes then why?
Q2.Why the following program is producing outuput as “DATA is 0″ ?
void main()
{
char data;
scanf(“Data is %c”,&data);
printf(“Datais %d”,data);
}