Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6739563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:30:13+00:00 2026-05-26T11:30:13+00:00

Its a homework, sorry for that. I can’t make working program for counting chars

  • 0

Its a homework, sorry for that.
I can’t make working program for counting chars in word, for an example:

  • I enter the String : My name is peter
  • The program asks which word to process..
  • I enter the number : 3
  • Program says : Count of the Third word is 2.

#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
  char text[200],vards[20];
  int i, length,lengthv, count=0,x;
  printf("insert txt\n");
  gets(text);
  length=strlen(text);
  for(i=0; i<length; i++)
   {
    if(text[i]!=' ' && text[i]!='.' && text[i]!=',')
      {
        printf("%c", text[i]);
      if (text[i+1]=='\0') 
              count++;
      }
   else
     {
        if(text[i-1]!=' ' && text[i-1]!='.' && text[i-1]!=',')
          {
            count++;
            printf("\n");
          }          
     }
   }
  printf("detect lenght of wich name\n");
  for(i=0;i<x;i++);
  scanf("%s", &text);
  lengthv=strlen(vards);
  printf("\n The lenght of name is %d", lengthv);
  getch();
  return 0;
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:30:14+00:00Added an answer on May 26, 2026 at 11:30 am

    I can’t really understand your code, but here is how I would do it:

    #include <stdlib.h>
    #include <stdio.h>
    
    int main() {
      char text[200], whichText[200];
      int i=0, length, countWord=0, currWord=1, wordChars=0;
    
      // Get text input:
      printf("insert txt\n");
      gets(text);
      length=strlen(text);
    
      // Get word to count:
      while(countWord == 0) {
        printf("Count which word?\n");
        gets(whichText);
        sscanf(whichText, "%i", &countWord);
      }
    
      // Iterate through each character of the text input:
      for( i=0; i < length; i++ ) {
        // Keep track of which word we are on, by counting spaces:
        if( text[i] == ' ' ) {
          currWord ++;
          continue;
        }
        // While we are on the desired word, count the characters:
        if( currWord == countWord )
          wordChars ++;
      }
    
      printf("Count of word %i is %i.\n", countWord, wordChars);
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am thinking of working on an online homework submission system where students can
Here is my homework question: Write a program that asks for a film name
I'm working on homework for a automata theory class. So far its just proofs
I'm working on a cluster analysis program that takes a set of points S
I'm trying to solve this problem, its not a homework question, its just code
its out of question that a dao will not hold any state. however, for
hmm i got a homework, its 2 hours and i still have no clue
I made this program just out of interest and wanted to make it better.
XXX----Yep, its a Homework problem, but yea I'm stuck. Why doesn't this print out
Here is my code, pretty simple really. Its not homework, I'm teaching myself java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.