Hi all,
I've been working on this code since morning and seems like I need stronger skills on pointers n arrays.
I'm trying to read the content of a config file, which has x lines and then pass it to an array of characters.
Not really sure if I did use the strtok function correctly, but here's what I got so far..
This is the config file's content:
This is the output of the code:
I've been working on this code since morning and seems like I need stronger skills on pointers n arrays.
I'm trying to read the content of a config file, which has x lines and then pass it to an array of characters.
Not really sure if I did use the strtok function correctly, but here's what I got so far..
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mysql.h>
#define MAXLENGTH 1024
char *extarray[20];
char temp[50];
int add2array(char*,int);
int add2array(char *a, int b)
{
printf("add2array...\n");
sprintf(temp,a);
extarray[b] = temp;
return 0;
}
int main( int argc, char *argv[] )
{
char *v_file = "/home/abuser/configpolicy.txt";
char *token;
char line[256];
int linenum = 0;
FILE * _file;
int a;
// THIS PART GETS THE DETAILS FROM config file
_file = fopen(v_file, "r");
if(_file == NULL)
return -1;
while(fgets(line, 256, _file) != NULL)
{
char ext[256];
if(sscanf(line,"%s", ext) != 1)
{
fprintf(stderr, "syntax err-line %d\n", linenum);
continue;
}
token = strtok(ext,";");
a=0;
while(token!=NULL)
{
//getDirHash(token);
//extarray[linenum]=token;
if(a == 0)
add2array(token,linenum);
token = strtok(NULL,";");
a++;
}
linenum++;
}
// END
for(a=0;a<4;a++)
printf("array %d is %s\n", a,extarray[a]);
return 0;
}
Code:
.txt;new;delete .txt;tamper;restore .exe;new;delete .exe;tamper;restore
Code:
add2array... .txt add2array... .txt add2array... .exe add2array... .exe array 0 is .exe array 1 is .exe array 2 is .exe array 3 is .exe
Comment