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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:43:23+00:00 2026-05-31T17:43:23+00:00

The program is supposed to take a file, say data.dat, filled with a list

  • 0

The program is supposed to take a file, say data.dat, filled with a list of up to 320 words all less than or equal to 29 characters (30 with the null character) and add each of those words to a global array. Then I want to sort that list alphabetically with a bubble sort. I did so with the following function in its own file sort.c

#include "set.h"
#include "sortAndSearch.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>

void bubbleSort(char A[][30], int num) {
int i, j;
char temp[30];

for(i = 0; i < num; i++)
    for(j = 0; j < num-1; j++)
        if(strcmp(A[i], A[i+1]) > 0){
            //swap the two array elements
            strcpy(temp, A[j]);
            strcpy(A[j], A[j+1]);
            strcpy(A[j+1], temp);
        }
}

I need a set of unsigned ints

unsigned int Set[10];

to act as an index for the names array. So each unsigned int has 32 bits and there are 10 unsigned ints for a total of 320 bits and each bit will reference a word. I am unsure how to approach this part.

The end goal is to create functions to manipulate the sets. I feel like I can attack that myself if I can get the sorting and index down, as I’ve done something similar but without using character arrays. The contents of the header file set.h that defines the functions to be used follows

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

// defining new type(s)
typedef unsigned int Set[10];

// declaring global variable(s)
extern char names[320][30];

extern void setUnion(Set set1, Set set2, Set result);
extern void setIntersection(Set set1, Set set2, Set result);
extern void clearSet(Set set);
extern void add2Set(Set set, int value);
extern void deleteFromSet(Set set, int value);
extern int isMember(Set set, int element);
extern void printSet(Set);
extern int nameIsMember(Set set, char *);
extern void addName2Set(Set set, char *);
extern void deleteNameFromSet(Set set, char *);

And here are the contents of the header file sortAndSearch.h

void bubbleSort(char A[][30], int num);

int binarySearch(char A[][30], char *, int, int );
  • 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-31T17:43:25+00:00Added an answer on May 31, 2026 at 5:43 pm

    Your bubble sort is in fact not a bubble sort. It only makes a single pass over the array. You need to repeatedly pass over the array until you make a pass that does not result in a swap. At that point you know that your array is ordered.

    My preferred bubble sort implementation has an outer do loop. The inner loop is just as you currently have. The outer loop terminates when the latest inner loop execution failed to swap any items.

    Of course, I’d recommend using a better sorting algorithm in the long run, but this is probably a homework assignment.

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

Sidebar

Related Questions

I have code that is supposed to take all the user data that was
I am supposed to write a program in JavaScript to find all the anagrams
I am writing a program in C++ which is supposed to take an input
The program is supposed to take user input, turn it into html and pass
So, this program is supposed to take stats from Auburn's football season and compute
I have a button in my program that, when pressed, is supposed to take
I've been trying forever to get this working. The program is supposed to take
I have a program that's supposed to take values and print them back out.
This program is supposed to take in a three digit number and change it
My program is supposed to read a text document with a bunch of numbers

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.