Question

How to find the length of an integer string in C language? I know that the...

How to find the length of an integer string in C language?

I know that the strlen() function only works for finding the length of a regular string, but I want to know how to find the length of an integer string in C language.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.

#include <stdio.h>
int integer_length(int num)
{
int ct=0;
while(num!=0)
{
ct++;
num=num/10;
}
return ct;
}

int main()
{
int num=12345;
printf("length of %d is %d\n",num,integer_length(num));

return 0;
}

main.c } 1 #include <stdio.h> 2 int integer_length(int num) 3- { 4 int ct=0; 5 while(num! =) 6 { 7 ct++; 8 num num/10; 9 10 r

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
How to find the length of an integer string in C language? I know that the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Programming language C - How would I convert my words char array into a string...

    In Programming language C - How would I convert my words char array into a string array so I can use the strcmp() function and alphabetically sort the words? #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, char*argv[]){ int i =0; int j =0; int count =0; int length = strlen(argv[1]); for(i =0; i < length; i++){ if(isalpha(argv[1][i]) == 0 ||isdigit(argv[1][i] != 0)){ count ++; } printf("%c",argv[1][i]); } char *strings; int wordNum =0; int charNum =0; strings...

  • How to return a form of the string in C++?? I know that string function has...

    How to return a form of the string in C++?? I know that string function has to return a string like an int function returns an int variable.     let's say I have a function named string printCircle(int number). In this function, how to return a form of the string as a circle?

  • In C Programming Language In this lab you will implement 4 string functions, two using array...

    In C Programming Language In this lab you will implement 4 string functions, two using array notation and two using pointers. The functions must have the signatures given below. You may not use any C library string functions. The functions are 1. int my strlen (char s ) - This function returns the number of characters in a string. You should use array notation for this function. 2. int my strcpy (char s [], char t I)- This function overwrites...

  • Write a function that can return the length of a string in C language. Please leave...

    Write a function that can return the length of a string in C language. Please leave comments to explain the code and verify that it runs properly... Example: Input String: China The length of the string is 5. #include <stdio.h> int length(char * p) {     /write your code here } main(){     int len;     char str[20];     printf("Input string:");     scanf("%s", str);     len = length(str);     printf("The length of string is %d. ", len);     getchar();    ...

  • 1. String Length Write a function that returns an integer and accepts a pointer to a...

    1. String Length Write a function that returns an integer and accepts a pointer to a C-string as an argument. The function should count the number of characters in the string and return that number. Demonstrate the function in a simple program that asks the user to input a string, passes it to the function, and then displays the function’s return value. c++

  • [C++ Language] Define a function to find the largest element from an integer array.

    [C++ Language] Define a function to find the largest element from an integer array.

  • I know how to do a) and b) but unsure about c) c) Number of strings...

    I know how to do a) and b) but unsure about c) c) Number of strings that (do not not contain "cab" or "bac" BUT may contain repeated consecutive letters), OR (strings that do not contain repeated consecutive letters but may contain "cab" or "bac"). Question 3. (5 marks) A language L is defined over a set of three letters {a, b, c}. A string ordering matters (i.e. "abc" is not equal to "bca"). The length of a string is...

  • Write two (2) overloaded functions that find a string in another string (first function) and find...

    Write two (2) overloaded functions that find a string in another string (first function) and find an integer in an integer array (second function). These should be value returning functions that return: For the string find, the string value if found, “not found” if the string is not found. For the integer file, the value if found or -1 if not found. The string function will pass in a string to find and the containing string, e.g. the request could...

  • Question 9. Consider the language {a"b" : n >0}. (i) Is this a regular language? Why...

    Question 9. Consider the language {a"b" : n >0}. (i) Is this a regular language? Why or why not? (ii) Is this a recursively enumerable language? Why or why not? Question 10. Consider the function defined by f(n) = 2 where n is a positive integer. (i) Can this function be computed by a Turing machine? Why or why not? (ii) Is this function primitive recursive? Why or why not?

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT