My program:
Code:
#include <stdio.h>
#include <stdlib.h>
char *pins[1][1777];
int load(char *name)
{
FILE *f;
f = fopen(name, "r");
if(f == NULL) return -1;
char str[8];
char *tmp;
int i=0;
while( fgets(str, 9, f) != NULL)
{
if(str[0] == '\n') continue;
tmp = str;
pins[0][i] = tmp;
i++;
}
return 0;
}
int main(int argc, char *argv[])
{
if(argc != 3) { printf("Usage: %s [file] [mac]\n", argv[0]); return 1; }
if(load(argv[1]) == -1) {
printf("Error load file\n"); return 1;
}
char cmd[100];
for(int i=0; i<1777; i++)
{
sprintf(cmd, "wpa_cli wps_reg %s %s", argv[2], pins[0][i]);
printf("%s\n", cmd);
}
return 0;
}
I ran the program and saw such rubbish:
Code:
wpa_cli wps_reg s @�Ϫ�
wpa_cli wps_reg s @�Ϫ�
wpa_cli wps_reg s @�Ϫ�
wpa_cli wps_reg s @�Ϫ�
wpa_cli wps_reg s @�Ϫ�
wpa_cli wps_reg s @�Ϫ�
wpa_cli wps_reg s @�Ϫ�
wpa_cli wps_reg s @�Ϫ�
wpa_cli wps_reg s @�Ϫ�
wpa_cli wps_reg s @�Ϫ�
wpa_cli wps_reg s @�Ϫ�
wpa_cli wps_reg s @�Ϫ�
wpa_cli wps_reg s @�Ϫ�
And each launch displays a different nonsense!
I replaced these lines:
Code:
tmp = str;
pins[0][i] = tmp;
on:
Code:
sprintf(pins[0][i], "%s", str);
And the segmentation error comes out!I read a book on it, but there it was not taught to me on any page for the whole book, and how to work with strings in C if it is so difficult?
In general, help me to solve this problem !!