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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:11:34+00:00 2026-06-12T12:11:34+00:00

On my school assignment i have to find a string with a brute force

  • 0

On my school assignment i have to find a string with a brute force algorithm.

If the length is, for example , 3 these are all the possible combinations:
a
b
c
aa
ba
ca
ab
bb
cb
ac
bc
cc
aaa
baa
caa
aba
bba
cba
aca
bca
cca
aab
bab
cab
abb
bbb
cbb
acb
bcb
ccb
aac
bac
cac
abc
bbc
cbc
acc
bcc
ccc

I having problems in strcat.

here is the code.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
# define PASS_SIZE 3


char letters[] = "abc";
char test[] = "acb";
int count = 0;
int nbletters = sizeof(letters)-1;
int bruteForce(int size);

int main() {
    int i = 0;
    int notFound = 1;

    for (i = 1; i <= PASS_SIZE && notFound == 1; i++){
        notFound = bruteForce(i);
    };

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

    return -1;
}

int bruteForce(int size){
    int i;
    int entry[size];
    char pass[50];
    char *temp;

    for(i=0 ; i<size ; i++){
        entry[i] = 0;
    }
    do {
        for(i=0 ; i<size ; i++){
            temp = letters[entry[i]];
            printf("%c", temp);
            strcat(pass,temp); /*Getting error here*/
       }

        count++;
        printf("\n");

        /*Compare pass with test*/
        if (strcmp (pass,test) == 0){
            return 0;
        };

       for(i=0 ; i<size && ++entry[i] == nbletters; i++){
            entry[i] = 0;
        }

    } while(i<size);

    return 1;
}

Probably the brute force algorithm is not the best one.

Why isn’t strcat working and I’m getting segmentation foult?

  • 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-12T12:11:36+00:00Added an answer on June 12, 2026 at 12:11 pm

    You are declaring your pass variable but you are not initializing it. When you concatinate onto its end, you’re assuming initially its end is its start, but you need to make that be the case.

    More importantly, take a look at your temp variable. You’ve declared it to be a char *, but you’ve initialized it to be a char (instead of pointing to a char), and then in strcat() you treat it like a pointer again — but it’s not pointing anywhere valid (causing your crash).

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

Sidebar

Related Questions

I have to implement a search algorithm for a school assignment. Right now, i'm
We have a school assignment and we were told that all numbers end after
For a school assignment I have to create a C++ program that will create
Hello is have a question for a school assignment i need to : Read
I have an assignment for school, and I'm not sure how the teacher wants
I'm writing a little genetic algorithm in Java, as a school assignment. Up until
What's a clear way of doing this? For a school assignment I have to
For a school assignment, we have to make a Usecase diagram. But the documentation
We have to create an application for iPhone and Android as a school assignment.
I have the following directory structure: folder1/ folder2/ compiler.java For a school assignment, we

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.