Kjell, Chapter 24, Exercise 1 String Length. For any additional info click on te
ID: 3682483 • Letter: K
Question
Kjell, Chapter 24, Exercise 1 String Length. For any additional info click on textbooklink.(http://chortle.ccsu.edu/assemblytutorial/Chapter-24/ass24programs.html)
Write a program that repeatedly asks the user for a string and then calculates and prints out the string length. Stop the program when the string is empty (when the user hits "enter" without anything else on the line.) Be sure to reserve enough memory in the .data for the string. Use indexed addressing to scan through the string. Strings read in with the trap handler service include a ' ' character at the end, followed by the null termination. Don't count the ' ' or the null as part of the string length.
Explanation / Answer
#include<stdio.h>
int main()
{
char str[1000];
int length;
printf(" Enter the String : ");
gets(str);
length = 0; // Initial Length
if (str[length] != '')
length++;
printf(" Length of the String is : %d", length);
else
if (str[length] = '')
printf(" string is empty: ");
return(0);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.