answersLogoWhite

0

#include<stdio.h>

#include<string.h>

void main()

{

int count,i,len;

char str[100];

printf("enter the sentence");

gets(str);

len=strlen(str);

for(i=0;i<=len;i++)

{

while(str)

if(str[i]==' ') count++;

}

printf("the number of words are :\t%d",count+1);

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

Write a java program to count the space from the given line?

.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......


What program can be written to count the number of alphanumerics in a string?

public int getStringLength(String val) { return val.length(); } There is an inbuilt functionality in strings that counts the number of alphabets in a string called length()


C plus plus program to count digit in a string?

Use the following function to count the number of digits in a string. size_t count_digits (const std::string&amp; str) { size_t count = 0; for (std::string::const_iterator it=str.begin(); it!=str.end(); ++it) { const char&amp; c = *it; if (c&gt;='0' &amp;&amp; c&lt;='9'); ++count; } return count; }


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

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; #include&lt;string.h&gt; void main() { char string[50]; int flag,count=o; clrscr(); printf("The grammar is: S-&gt;aS, S-&gt;Sb, S-&gt;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)&amp;&amp;(string[count]=='a')) { printf("The string does not belong to the specified grammar"); break; } else if(string[count=='a']) continue; else if(flag==1)&amp;&amp;(string[count]='\0')) { printf("The string accepted"); break; } else { printf("String not accepted"); } getch():


Write a program to count number of spaces in a string using array?

#include&lt;iostream&gt; #include&lt;string&gt; size_t count_spaces(std::string&amp; str) { size_t spaces=0; for(size_t i=0; i&lt;str.size(); ++i) if( str[i]==32 ) ++spaces; return( spaces ); } int main() { std::string str("This is a string with some spaces."); size_t spaces = count_spaces(str); std::cout&lt;&lt;"The string ""&lt;&lt;str.c_str()&lt;&lt;"" has "&lt;&lt;spaces&lt;&lt;" spaces.\n"&lt;&lt;std::endl; }

Related Questions

Write a java program to count the space from the given line?

.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......


How do you write c program to accept a string from the console and count number of vowels constants digits tabs and blank spaces in a string?

Read the characters one at a time, and write an "if" for each of the cases. In each case, if the condition is fulfilled, increment the corresponding counter variable.


What program can be written to count the number of alphanumerics in a string?

public int getStringLength(String val) { return val.length(); } There is an inbuilt functionality in strings that counts the number of alphabets in a string called length()


C plus plus program to count digit in a string?

Use the following function to count the number of digits in a string. size_t count_digits (const std::string&amp; str) { size_t count = 0; for (std::string::const_iterator it=str.begin(); it!=str.end(); ++it) { const char&amp; c = *it; if (c&gt;='0' &amp;&amp; c&lt;='9'); ++count; } return count; }


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

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; #include&lt;string.h&gt; void main() { char string[50]; int flag,count=o; clrscr(); printf("The grammar is: S-&gt;aS, S-&gt;Sb, S-&gt;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)&amp;&amp;(string[count]=='a')) { printf("The string does not belong to the specified grammar"); break; } else if(string[count=='a']) continue; else if(flag==1)&amp;&amp;(string[count]='\0')) { printf("The string accepted"); break; } else { printf("String not accepted"); } getch():


Write a c program to count the number of word in a string?

#include&lt;stdio.h&gt; void main() { int cnt=0,i; char str[100]; printf("Enter the string "); scanf("%s",str); for(i=0;i&lt;strlen(str)-1;i++) { if(str[i]==' ') cnt++; } printf("\nTotal no. of word in string = %d",cnt); }


It 4-1 solved question papers November -2008?

Write a program to count the number of IS in any number in register B and put the count in R5.


Read a stringcount and print number of 'a's in the string?

To count the number of 'a's in a string, you can use the count() method in Python. For example, if you have a string my_string, you can get the count of 'a's by using my_string.count('a'). This will return the total number of occurrences of the letter 'a' in the string. Finally, you can print the result using the print() function.


Write a program to count number of spaces in a string using array?

#include&lt;iostream&gt; #include&lt;string&gt; size_t count_spaces(std::string&amp; str) { size_t spaces=0; for(size_t i=0; i&lt;str.size(); ++i) if( str[i]==32 ) ++spaces; return( spaces ); } int main() { std::string str("This is a string with some spaces."); size_t spaces = count_spaces(str); std::cout&lt;&lt;"The string ""&lt;&lt;str.c_str()&lt;&lt;"" has "&lt;&lt;spaces&lt;&lt;" spaces.\n"&lt;&lt;std::endl; }


What is the program to find the number of each word in the string array?

#include&lt;iostream&gt; #include&lt;string&gt; using namespace std; int main() { int count=0; string b; string a[6]={"technical","school","technical","hawler","school","technical"}; for(int i=0;i&lt;6;i++) { b=a[i]; for(int j=i;j&lt;6;j++) { if(a[j]==b) count++; } cout&lt;&lt;a[i]&lt;&lt;" "&lt;&lt;count&lt;&lt;endl; count=0; } return 0; }


How to write a C Program that will count the number of times 1 occur?

There are some ways to do it. Here I give you an example. You can do it if you take the input as string. #include &lt;stdio.h&gt; #include &lt;string.h&gt; main(void) { int i, count = 0; char ch[10000]; gets(ch); int len = strlen(ch); for(i = 0; i &lt; len; i++) { if(ch[i] == '1') { count++; } } printf("Number of times one occurs: %d\n", count); }


Write a program to accept a string from keyboard and count and display the numbers of vowels present in the string by using function?

You need to scan through the string and keep track of the vowelsoccurring. Here is a sample program:#include#includeint countVowels(char[] s){int count = 0, i;for( i=0; char[i] != '\0'; i++){switch(char[i]){case 'a':case 'e':case 'i':case 'u':case 'o': count++;break;}}return count;}int main(){char str[256];printf("Enter the string:\t");scanf("%s", str);printf("The number of vowels in the string are :%d\n", countVowels(str));return 0;}