Question: Write a C program that accepts a string of characters from user and calculates the length of the string using pointers. Example: Input a string:

Write a C program that accepts a string of characters from user and calculates the length of the string using pointers. Example: Input a string: C Programming Language Expected Output: The length of the given string C Programming Language is 22

MY CODE SO FAR IS BELOW. I WOULD APPRECIATE IF YOU COULD TROUBLESHOOT THE CODE BELOW AND TELL ME WHAT I DID WRONG.

#include "pch.h"

#include

#include

int strLen(char *s);

int main()

{

char str[100];

char *s;

s = str;

printf("Enter the string..? ");

scanf_s("%s", s);

int x = strLen(s);

printf("Length of string is=%d ", x);

}

int strLen(char *s)

{

char *p = s;

while (*p != '\0')

{

p++;

}

return p - s;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!