I'm trying to loop through a text file (seven lines in the file, with aaaa, aaab, aaac, etc listed) with password guesses for pset2 Crack. I am able to open the file, and iterate through the lines. However, my output is not what I expect at all. Here is the relevant code:
FILE* list = fopen("test.txt", "r");
char line[7]; //amount of lines in list.txt 456975
// iterate through each line of the file
while (fgets(line, sizeof(line), list))
{
char nline[3] = ""; //initialize "new line" that will be used to hold string
sscanf(line, "%s", nline); //convert the contents of "line" into a string and read it
string guess = strcat(salt, nline); // catenate the salt to the front of the guess
printf("%s\n", guess);
}
printf("%s\n", hash);
and the output that I get is this:
50aaaa
50aaaaaaab
50aaaaaaabaaac
50aaaaaaabaaacaaad
50aaaaaaabaaacaaadaaae
50aaaaaaabaaacaaadaaaeaaaf
50aaaaaaabaaacaaadaaaeaaafaaag
50aaaaaaabaaacaaadaaaeaaafaaagaaah
Segmentation fault
I've tried using the debugger in the ide, but I can't figure that out (if you can point me to a good tutorial on that, I'd appreciate it).
I'm really just looking for where to start debugging here. I sat with this for 2 hours last night and can't make any headway. I know it has something to do with not looping correctly, as I should only see "aaaa" once, but it seems to be adding on the new line and printing a catenation of that instead of just a single guess per line. I expected to see:
50aaaa
50aaab
50aaac
....
The segmentation fault is throwing me for a loop (no pun intended) as well. I don't mind pouring over documentation and I'm not looking for a quick fix here, I just feel like I'm spinning and need to pointed in the right direction. Thanks in advance!
fgets()
? – Mayonnaise2124 Mar 26 '19 at 3:44