I keep getting a segmentation error when I try to add a character to the string test. I have tried multiple iterations and can't figure out why I get the error. I tried having the test set to \0
. I can't figure out how I am accessing outside test.
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
#define _XOPEN_SOURCE
#include <unistd.h>
#include <crypt.h>
//this intializes the argument count and argument vector
int main(int argc, string argv[]) {
//this makes sure it is a string
if (argv[1] != NULL) {
//this makes sure that the user typed 2 arguments,
// the second being the keyword
if (argc != 2) {
printf("no hash inputed\n");
return 1;
}
//main program once the keyword has been verified
int h_len = strlen(argv[1]);
string hash = argv[1];
string test = "A";
int p_len = 0;
printf("H len is %i and P len is %i\n", h_len, p_len);
printf("%s and test: %s\n", hash, test);
//this will iterate through the 1st space and test the charachters
for (int j = 0; j < 4; j++) {
//iterates through the characters that can be used in the password
//for (int i = A; i < z; i++)
//for (char ch = 'A' ; ch <= 'z' ; ch == 'Z' ? ch = 'a' : ++ch )
for (char i = 'A'; i <= 'z'; i++) {
//this skips the ASCII inbetween Z and a
if (i > 'Z' && i < 'a') {
i = 'a';
}
printf("%c", i);
//test[j] = test[j] + (char)i;
test = strncat(test, &i, 1);
printf(" test is %s\n", test);
...