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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:48:12+00:00 2026-06-14T15:48:12+00:00

This function is supposed to get a parameter as the pointer of a file

  • 0

This function is supposed to get a parameter as the pointer of a file and put all file into the struct anagram, then write it to another file. Right now the data only contains
a.word, but it suppose to containst a.sorted too?

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include "anagrams.h"


void buildDB ( const char *const dbFilename ) 
{
    FILE *dict, *anagramsFile;
    struct anagram a;

    //check if dict and anagram.data are open
    errno=0;
    dict= fopen(dbFilename, "r");

    if(errno!=0) {
        perror(dbFilename);
        exit(1);
    }

    errno=0;

    anagramsFile = fopen(anagramDB,"wb");

    char word[SIZE];
    char *pos;
    int i=0;

    while(fgets(word, SIZE, dict) !=NULL) {

        //get ripe of the '\n'
        pos=strchr(word, '\n');
        *pos = '\0';

        strncpy(a.word,word,sizeof(word));
        //lowercase word
        int j=0;
        while (word[j]) {
            tolower(word[j]);
            j++;
        }

        /* sort array using qsort functions */ 
        qsort(word,strlen(word), 1, charCompare);

        strncpy(a.sorted,word,sizeof(word));

        fwrite(&a,1,sizeof(word),anagramsFile);

        i++;
    }
    fclose(dict);
    fclose(anagramsFile);

}

data:

enter image description here

  • 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-14T15:48:14+00:00Added an answer on June 14, 2026 at 3:48 pm
    char word[SIZE];
    ...
    fwrite(&a,1,sizeof(word),anagramsFile);
    

    sizeof(word) returns the full size of the buffer, so you’re writing the full length of the buffer each time. You’ll want to use strlen() or similar to only write the part of the buffer you’re actually using.

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

Sidebar

Related Questions

I have C function that takes string pointer as a parameter. This functions returns
I have this function which is supposed to set a certain time format to
I've had trouble writing this code. I'm supposed to make a function that can
Suppose I have this html markup: <div id=wrapper> <pre class=highlight> $(function(){ // hide all
Function description here. I'm struggling to get it right to call this function from
Suppose I have this function: void my_test() { A a1 = A_factory_func(); A a2(A_factory_func());
Suppose I have a utility function like this - public static boolean isABlankSpace(char c)
Suppose I have a function like this (I use akka 2.0.2): def foo(message: String):
Particularly the bit about live.... jQuery('.something').live('click', function() { jQuery(this).parent('form').reset(); }); I suppose this might
Suppose I have a function defined like this: class Foo() { public: void bar(MyClass*

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.