Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions

Question

Types of Interpersonal Relationships?

Answered: 1 week ago

Question

Define co-ordination?

Answered: 1 week ago

Question

What are the role of supervisors ?

Answered: 1 week ago