answersLogoWhite

0


Best Answer

printf does return the length:

size_t len = printf ("%s", str);

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Calculate length of string using printf statement only?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a program that give all the rotations of a string?

#include<stdio.h> #include<string.h> int main() { char a[80]; int rotated_element_number[80]; int rotation; int i; int length; printf("enter the word: \n"); gets(a); length = strlen(a); printf("the reversed string is:\n"); for( rotation=0; rotation<length; rotation++) { for( i=0; i<length; i++) { rotated_element_number[i] = i + rotation; while(rotated_element_number[i] > (length-1)) rotated_element_number[i] -= length; printf("%c", a[rotated_element_number[i]]); } printf("\t"); } getchar(); return 0; }


How to write printf statement for read characters into array str until the letter p is encountered?

In pseudo-code: while ( not(end of string) and letter(string at position X) is not 'P' ){ add(array, newposition) = letter(string at position X); }


Can you print string without using semi column in printf statement in c programming?

If you forget the semicolon, your program won't compile.


Program to find the size of the string in c?

int main (void) { char buf[1024]; scanf ("Enter a string: %s", buf); printf ("The length of the string is %d chars long.\n", strlen (buf)); return 0; }


How do you write a program to check the string of a given grammar?

#include<stdio.h> #include<conio.h> #include<string.h> void main() { char string[50]; int flag,count=o; clrscr(); printf("The grammar is: S->aS, S->Sb, S->ab\n"); printf("Enter the string to be checked:\n"); gets(string); if(string[0]=='a') { flag=0; for(count=1;string[count-1]!='\0';count++) { if(string[count=='b']) { flag=1; continue; } else if((flag==1)&&(string[count]=='a')) { printf("The string does not belong to the specified grammar"); break; } else if(string[count=='a']) continue; else if(flag==1)&&(string[count]='\0')) { printf("The string accepted"); break; } else { printf("String not accepted"); } getch():

Related questions

How do you display a text reversely in C language without using onlu simply input and output?

#include<stdio.h> #include<conio.h> void main() { char string[20]; int i=0; printf("Enter the string.\n"); while(i<=19) { scanf("%c",&string[i]); i++; } while(i>=0) { printf("%c",string[i]); i--; } getch(); } In this program it is compulsory to enter 20 characters. Now we can write a program in which it is not necessary. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char string[20]; int length; printf("enter the string.\n"); gets(string); length=strlen(string); length--; while(length>0) { printf("%c",string[length]); length--; } getch(); }


Write a program that give all the rotations of a string?

#include<stdio.h> #include<string.h> int main() { char a[80]; int rotated_element_number[80]; int rotation; int i; int length; printf("enter the word: \n"); gets(a); length = strlen(a); printf("the reversed string is:\n"); for( rotation=0; rotation<length; rotation++) { for( i=0; i<length; i++) { rotated_element_number[i] = i + rotation; while(rotated_element_number[i] > (length-1)) rotated_element_number[i] -= length; printf("%c", a[rotated_element_number[i]]); } printf("\t"); } getchar(); return 0; }


How to write printf statement for read characters into array str until the letter p is encountered?

In pseudo-code: while ( not(end of string) and letter(string at position X) is not 'P' ){ add(array, newposition) = letter(string at position X); }


WAP using function to print all the rotations of a given string in c language?

#include#include#includeint main() {char a[80];int rotated_element_number[80];int rotation;int i;int length;printf("Enter the word: \n");gets(a);printf("%s\n",a);length = strlen(a);printf("Length is %d\n", length);for( rotation=0; rotation


What is null string?

main(){ char str[5]="hello"; if(str==NULL) printf("string null"); else printf("string not null"); }


Can you print string without using semi column in printf statement in c programming?

If you forget the semicolon, your program won't compile.


What is is null?

main(){ char str[5]="hello"; if(str==NULL) printf("string null"); else printf("string not null"); }


Why printf is used instead of print in c?

The printf() function prints a formatted string.


A C program to print the number of words from given String?

/*We can calculate this with a lot of methods I'll explain only one of them */ *str = "abcd"; // this is a input string printf("%d", strlen(str));


Program to find the size of the string in c?

int main (void) { char buf[1024]; scanf ("Enter a string: %s", buf); printf ("The length of the string is %d chars long.\n", strlen (buf)); return 0; }


How do you write a program to check the string of a given grammar?

#include<stdio.h> #include<conio.h> #include<string.h> void main() { char string[50]; int flag,count=o; clrscr(); printf("The grammar is: S->aS, S->Sb, S->ab\n"); printf("Enter the string to be checked:\n"); gets(string); if(string[0]=='a') { flag=0; for(count=1;string[count-1]!='\0';count++) { if(string[count=='b']) { flag=1; continue; } else if((flag==1)&&(string[count]=='a')) { printf("The string does not belong to the specified grammar"); break; } else if(string[count=='a']) continue; else if(flag==1)&&(string[count]='\0')) { printf("The string accepted"); break; } else { printf("String not accepted"); } getch():


Wapto input two strings and then combine it into one string?

#include#include#includevoid main(){char a[20],b[20];clrscr();printf("Enter String a: ");gets(a);printf("Enter String b :");gets(b);printf("%s",strcat(a,b));getch();}