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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:27:27+00:00 2026-06-05T20:27:27+00:00

OK, I’m working on a spellcheck program in C. The bit I’m having trouble

  • 0

OK, I’m working on a spellcheck program in C. The bit I’m having trouble with is reading a word from the system dictionary into the program. I’ve searched for an answer but I couldn’t find anything quite right, probably because this is a pretty rudimentary thing. Here’s the code I’ve got so far.

void readWord(FILE * stream, int buffer[]){
15   
16   while(fgetc(stream) != 10){
17     buffer[i] = fgetc(stream);              
18     printf("copying %d to buffer\n", buffer[i]);    //added for debugging
19   }
20   return;
21 }

Here are the variables used in the function call along with the call

int buffer[WIZE];
readWord(dictionary, buffer, WSIZE);

dictionary is pointing to /usr/share/dict/words, and there’s code to make sure it opens correctly but I didn’t put it in this question; maybe that’s the problem after all. This should output Aarhus, but instead it outputs:

Dictionary opened successfully
copying 97 to buffer
copying 104 to buffer
copying 115 to buffer

I’m wondering if each time the program executes line 16 the file position gets updated to the next character? The output is every other letter of Aarhus, if the pointer is starting at the second character.

The readWord function is also used to read individual words from the text files to check, which is the reason I didn’t use getline. There are other functions to flush the buffer to a string along with the terminal null character, and display. This is just the bit that deals with getting one word at a time from files.

  • 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-05T20:27:29+00:00Added an answer on June 5, 2026 at 8:27 pm
    while(fgetc(stream) != 10){
    

    In the while condition you are reading a character that is not saved to anywhere. Then, you read another one in the body, so you are reading 2 characters per iteration and saving only one.

    Also, you are storing the character in buffer[i], but i is not being increased. Try this:

    while((buffer[i] = fgetc(stream)) != 10){
         printf("copying %c to buffer\n", buffer[i]);    //added for debugging
         i++;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have an autohotkey script which looks up a word in a bilingual dictionary
I am currently running into a problem where an element is coming back from
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into

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.