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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:42:18+00:00 2026-06-08T23:42:18+00:00

#include <stdio.h> #include <ctype.h> void readFile(FILE *file); void count (FILE *file, int *alpha, int

  • 0
#include <stdio.h>
#include <ctype.h>

void readFile(FILE *file);
void count (FILE *file, int *alpha, int *digit, int *punct, int *spaces);
void printMessage(int *alpha, int *digit, int *punct, int *spaces);

int main( void ) {
FILE *file = NULL;
readFile(file);
return 0;
}

void readFile(FILE *file) {
file = fopen("/Users/AdmiralDanny/Desktop/testFile.txt", "r");
int *alpha = NULL, *digit = NULL, *punct = NULL, *space = NULL;
if (file) {
  count(file, alpha, digit, punct, space);
  fclose(file);
} else {
  perror( "error opening the file" );
}
}

void count (FILE *file, int *alpha, int *digit, int *punct, int *spaces) {
  int ch;

 while ((ch = fgetc(file)) != EOF ) {
   if (isalpha(ch) != 0) {
  ++alpha;
  } else if (isdigit(ch)) {
  ++digit;
  } else if (ispunct(ch)) {
  ++punct;
  } else if (isspace(ch)) {
    ++spaces;
  }
}
 printMessage(alpha, digit, punct, spaces);
}

void printMessage(int *alpha, int *digit, int *punct, int *spaces) {
printf( "alphabetic characters: %d\n", alpha );
printf( "digit characters: %d\n", digit);
printf( "punctuation characters: %d\n", punct );
printf( "whitespace characters: %d\n", spaces );
}

my .txt file only has 4 spaces and 12 alphabet character, but it gives me 48 alphabetic characters and 8 white space characters? why is this happening?
also, i get a warning when i tried to print out the int pointeres in printMessage method

  • 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-08T23:42:20+00:00Added an answer on June 8, 2026 at 11:42 pm

    No memory has been allocated for any of the ints and the count() function is just incrementing the int pointers not an int value:

    ++spaces; /* spaces is an int* so this increments the pointer. */
    

    You could use malloc(), but it would simpler to stack allocate and pass the addresses in.

    int alpha = 0, digit = 0, punct = 0, space = 0;
    count(file, &alpha, &digit, &punct, &space);
    

    and in count():

    (*spaces)++;
    

    dereference the ints for incrementing and dereference for printing:

    printf( "whitespace characters: %d\n", *spaces);
    

    As the caller of count() does not require the updated values of the ints, just pass by value and forget about pointers altogether (same for printMessage()).

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

Sidebar

Related Questions

#include <stdio.h> #include <ctype.h> #define STRING_LEN 500 void stripspaces(char, char, char); int main(void) {
#include <stdio.h> #include <string.h> #include <ctype.h> void delspace(char *str); int main() { int i,
#include <stdio.h> #include <stdlib.h> int main(void) { int x; int *in, *begin; in =
#include <stdio.h> void wrapperPrint(char* s) { printf(s); return; } int main() { wrapperPrint(Hello world\n);
My code #include <stdio.h> #include <stdlib.h> #include <ctype.h> void getData(short int *number, char *string)
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
#include<stdio.h> #include<math.h> int main(int argc, char **argv){ // read in the command-line argument double
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { if(argc != 2) return
#include<stdio.h> #define N (sizeof(array) / sizeof(array[0])) main() { int array[5]={1,2,3,4,5}; int d; for(d=-1;d <=
#include <stdio.h> #include <ctype.h> int isPalindrome( char *str, int length ) { if (

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.