Hey I need some help with a function again. I have a text file I'm reading lines from. Each line has a web address and a encrypted password separated by a comma with a comma also at the end like this;
facebook.com,eYV^RecZi#),
youtube.com,eYV^RecZi#),
google.com,eYV^RecZi#),
Code:
FILE *list = fopen("list.txt", "r");
char input[40] = "";
fgets(input, 40, list);
while (fgets(input, 40, list)) {
input[strcspn(input, "\r\n")] = '\0';
//printf("%s\n", input);
int hold = 0;
char name[40] = "";
char pass[40] = "";
for (int i = 0; input[i] != ','; i++){
name[i] = input[i];
hold = i;
}
hold = hold + 2;
for (int n = hold; input[n] != ','; n++){
pass[n] = input[n];
}
printf("%s\n", name);
printf("%s\n", pass);
printf("%d\n", hold);
I'm trying to use 2 for loops to separate it back into two separate variables. Passing each character of the web address to a array until a comma is reached. Then the comma is skipped over and a second for loop dose the exact same thing for the password.
Its working fine for the address but for some reason the password is blank even though its the same for loop just used twice.
I cant work out why the pass variable is blank when printed at the end.