Author -  Sai gowtham

How to find the length of a given string in C

In this tutorial, we are going to learn about two different ways to find the length of a string in C.

Using the strlen() function

The built-in strlen() function helps us to find the length of a given string that is defined inside the string.h header file.

The strlen() function takes the string as an argument and returns its length.

Example:

#include <string.h>
#include <stdio.h>

int main() {
  char user[10] = "Gowtham";
  int length = strlen(user);
  printf("User length: %u", length);
}

Finding the length manually using for loop and while loop

We can also find the length of a string without using the str_len() function, by manually looping through the each character in a string and store the count value in a variable.

For loop:

#include <stdio.h>

int main() {
    char user[10] = "Gowtham";
    int i = 0;
    for (i; user[i] != '\0'; i++);    printf("User length: %d", i);
    return 0;
}

While loop:

#include <stdio.h>

int main() {
    char user[10] = "Gowtham";
    int i = 0;
    while (user[i] != '\0'){      i++;    }    printf("User length: %d", i);
    return 0;
}

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY