This C Program uses recursive function & counts the number of nodes in a linked list. A linked list is an ordered set of data elements, each containing a link to its successor.
Here is the source code of the C program to count the number of nodes in a linked list. The C Program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* Recursive C program to find length of a linked list
*/
#include <stdio.h>
int find_len (char [], int);
int main ()
{
char str[100];
int len = 0;
printf ("Enter the string: \n");
scanf ("%[^\n]s", str);
len = find_len (str, 0);
printf ("The length of the given string is: %d\n", len);
return 0;
}
int find_len (char str[], int index)
{
static int l = 0;
if (str[index] == '\0')
return l;
else
l ++;
find_len (str, index + 1);
}
Enter the string: Sanfoundry C Programming The length of the given string is: 24 Enter the string: Programming Examples The length of the given string is: 20
Sanfoundry Global Education & Learning Series – 1000 C Programs.
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
If you wish to look at other example programs on Strings, go to C Programming Examples on Strings. If you wish to look at programming examples on all topics, go to C Programming Examples.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Apply for C Internship
- Apply for Computer Science Internship
- Check C Books
- Watch Advanced C Programming Videos
- Check Computer Science Books