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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started