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 7972287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:49:37+00:00 2026-06-04T07:49:37+00:00

This is my little snippet that is giving me problems: int main(int argc, char**

  • 0

This is my little snippet that is giving me problems:

int main(int argc, char** argv) {

char string[75] = {0};
char *pChar;
int count = 0;

printf("String: ");
fgets(string, sizeof string, stdin);

printf("Numero parole: %d\n", countWords(string, strlen(string)));

// Suddivido la stringa nelle varie parole
pChar = strtok(string, " ");
while(pChar){
    if(isWord(pChar, strlen(pChar))){

        count += strlen(pChar);

    }
    pChar = strtok(NULL, " ");

}

printf("Lettere totali: %d\n", count);

return (EXIT_SUCCESS);

}

The problem is that no value is being assigned to count variable. I know there is something wrong but I still don’t know what’s wrong.

Thanks for helping ^^

P.S. I’m currently learning C so this probably is a stupid question.

P.P.S. As requested here’s the isWord function: (nevermind the comments they’re in italian)

// Controlla se è una parola
int isWord(char string[], int length){

int i = 0;                  // Contatore
int countAlpha = 0;         // Se il carattere è alfabetico. Non vengono
                            // contate le parole che contengono numeri

// Inizio scorrendo tutta la stringa tranne l'ultimo carattere che è un
// terminatore di stringa
for(i; i < length - 1; i++){

    // Se il carattere è alfabetico allora aumento il contatore isAlpha
    if(isalpha(string[i])){

        countAlpha++;

    // Altrimenti il carattere non è una lettera
    } else {

        countAlpha = 0;

    }

}

if(countAlpha == i){

    return 0;

} else {

    return 1;

}

}

  • 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-06-04T07:49:41+00:00Added an answer on June 4, 2026 at 7:49 am

    If count is not incrementing then it is because of one of the following:

    a) strlen(pChar); returns 0

    b) if(isWord(pChar, strlen(pChar))) is never true

    c) while(pChar) is never valid

    You can validate what is working and what is not by making use of your interactive debugger and stepping through your code, line by line, as it executes.

    Based on your additional changes since this was first posted, it seems the trouble is in your isWord function. It seems that function is returning the opposite values that you meant. Change it so that the if(countAlpha == i) returns 1 (for true) and its else returns 0 (for false).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

found this little code snippet that seems to do what i want, but im
I have a little snippet that formats a date for a timestamp like this:
hi i have this little snippet of code i wrote that checks to see
This little PHP snippet is used to set a cookie that lets me determine
I've got this little snippet that I use for row highlighting on an XSLT
I have this cool little snippet that I found, which adds a shadow to
I wrote this little snippet that should format money but its failing on the
I have taken this little snippet straight out of some code I'm working on:
I'm playing around with list comprehensions and I came across this little snippet on
This is a little snippet from a little flash game I'm working on: This

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.