Incorrect file initialisation in C - c

I have a piece of coding that is giving me a error. The File pointer is throwing a NULL error although it is declared correctly.
int PySchFee(Acc *py_User)
{
FILE *py_Fp;
int acn_Num,sch_Id;
float amnt=0;
system("cls");
/* printf("Please enter Account Number\n");
scanf("%d",&acn_Num);
printf("Please enter School Id Number\n");
scanf("%d",&sch_Id);*/
printf("Please enter Amount to pay\n");
scanf("%f",&amnt);
if ((py_User->bal-amnt)>=1000)
{
py_User->bal= py_User->bal-amnt;
AppCharge(py_User);
Rcrd_Write(py_Fp,py_User,NULL);
Svetyp(py_User,amnt,py_Sch_Fee);
fclose(py_Fp);
return 1;
}
else
{
fclose(py_Fp);
Error(broke);
return 0;
}
}

You never assign anything to py_Fp, therefore it contains garbage and hence the crash.
You must write something like
py_Fp = fopen("myfile", "w") ;
before calling Rcrd_Write

You are using py_Fp before you initialize it, you should add a statement like py_Fp = fopen(...); before you actually use it, such as Rcrd_Write(py_Fp,py_User,NULL);.

Related

I am trying to split this code into two .c and one .h file, but the structure is not getting accesssed by the other .c file

I have made a code which runs perfectly fine in a single file but when I try to split the code into two .c and one .h file the makefile shows an error of UNDEFINED REFERENCE TO THE STRUCTURE which is global data.
How can I split this code into the .c and .h file such that the error of undefined reference does not pop and code runs smoothly?
I just need the split .c and .h files,I can make the .mk file, I am a beginner in makefile.
Here the command line argument is the name of the file from which the code reads information-emplyoyeeinfo.txt.
The error while running the makefile(4 .c and 1 .h files) is in the screenshot below:
employeeinfo.txt file has these contents (user name, ID, password, casualleave, medical leave, earned leave)
Ramesh,QW120345,PO56,10,15,7
Rajesh,QW120905,IO56,10,15,7
Kajal,JI456987,IWQ9,10,15,7
Harleen,HJ782013,ZM12,10,15,7
Jim,BN784569,KL45,10,15,7`
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
//this code works on ZERO INDEXING
int linematched;//global variable which stores the variable
void main2();//this containsthe main part of the code workings,its pupose is explained below just before the function
void final_print();//prints the details of the user on quitting the wizard
void quit();//this is one function which handles the termination of code prompting the user to take another trail
void again();//this function handles the login if user wishes to take another leave
void table(char file_n[]);//populating the structure from data elements from the file by using specific delimiter
int login();//this function verifies the password with the one present in the file database
int deduction(int linematched,int days,int type_of_leave);//this performs another validation and deducts the days user desires for taking the leave
struct Empdetials
{
char name[25];
char id[9];//onr extra character to store /n
char password[5];
int casual;//casual,medical,earned leave as per the question
int medical;
int earned;
}emp[5];//declaring array of structures which will later be populated using table() function
void main(int argc,char *argv[])//command line arguments takes the name of the file to be read
{
char file_name[30];
strcpy(file_name,argv[1]);
printf("%s\n\n",file_name);
table(file_name);//calling the function to initiate the process of filling a structure with all the data from the files
printf("--------------------------------HELLO-------------------------------\n");
printf("----------------------WELCOME TO LEAVE MANEGMENT SYSTEM--------------\n");
main2();//the use of this is explained below
}
/*main function has a call to table() and invoking main() for re-login used to reset the structure and the deductions were lost,so I copied
everything of the main function into another function called main2() which is basically the amin function without he table() invoking so the
structure is not resetted after every call from again() and quit() during Re-login and structure keeps a track of the deductions that happened and
in this way I also removed the Welcome sentence to the same user,but he main reason is to avoid rewriting of the structure on every call
and losing the deduction data*/
void main2()
{
int casualm=10;//defining the maximum possible leaves here
int medicalm=15;
int earnedm=7;
int leave_days=0;//handles the number of leaves that a user will enter
int choice=0;//type of leave is handled by this variable 1 is casual,2 is emergency,3 is earned
int log=0;//CHECKS IF LOGIN WAS SUCCESFULL OR NOT
int res=0;//CHECKS IF DEDUCTION WAS SUCCESFULL OR NOT
//-------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------
log=login();//login is invoked and log stores the value which determines wheter the ogin was succesful or not
if(log==1)//if log=1,implies that the login was succesful and the user was found
{
printf("PLEASE SELECT HE TYPE OF LEAVE YOU WANT TO TAKE\n");
printf("1.CASUAL LEAVE\n");
printf("2.MEDICAL LEAVE\n");
printf("3.EARNED LEAVE\n");
scanf("%d",&choice);
printf("PLEASE ENTER THE NUMBER OF LEAVES YOU WANT TO APPLY FOR\n");
scanf("%d",&leave_days);
}
else
{
printf("SORRY THE LOGIN CREDENTIALS DON'T MATCH WITH ANY USER\n\n\n");//when the login fails this message is displayed
again();//gives user another chance to take give the input
}
//first validation of the input values,this ompare the input with the largest value of holidays available
int flag=1;//this controls wheter the variable entetred is within the maximum limit and that decuction() function can be called
if(choice==1)
{
if(leave_days>casualm)
{
printf("THE ENTERED NUMBER OF DAYS CROSSES THE MAXIMUM LIMIT \n");
again();
flag=0;
}
}
else if(choice==2)
{
if(leave_days>medicalm)
{
printf("THE ENTERED NUMBER OF DAYS CROSSES THE MAXIMUM LIMIT \n");
again();
flag=0;
}
}
else if(choice==3)
{
if(leave_days>earnedm)
{
printf("THE ENTERED NUMBER OF DAYS CROSSES THE MAXIMUM LIMIT \n");
again();
flag=0;
}
}
else
{
printf("sorry!! wrong input\n");
again();
flag=0;
}
if(flag)//if the validation is succcesful the value of the variable remains 1 and this loop is entered
{
res=deduction(linematched,leave_days,choice);//if res==1 then thern the validation was succesful and then the deduction is called and parameter is passed
if(res==1)//if deduction was succesful then the
{
printf("DEDUCTION WAS SUCCESFUL\n\n");
again();
//final_print();
}
}
}
//I am trying to convert the file to a structure and then use the structure to access the data and I'm also using files to store the information
extern void table(char file_n[])//this function is responsible for populating the structure by reading the file
{
printf("%s\n\n",file_n);
FILE *fp;//definig a file pointer
char ch;
char line[256];//definig 256 here,any arbitary number can be used
char *token;//token pointer that points to the elements of a line
int tokenposition=0;//token here means the particular text separated by comma
int lineposition=0;//line here is the entire line which has entire details of the an emmployee
fp=fopen(file_n,"r");//opening the file in read mode as we are only accessing information and not rewrting it
//-------------------------------------------------------------------------------------------------------------------------------------------------
while(fgets(line,256,fp) !=NULL) //accessing the lines one by one and trying to recognize the end of a line
{
tokenposition=0;//when we tokenize the line we need the count to keep a track of where we are int he string
//printf("%s \n",line);//used to check which line is not being read by the compiler
token = strtok(line,",");
//this seperates a line into token(entity) based on a delimiter,here the delimiter is a comma
//strtok-tring tokenization method
while(token != NULL)
{
switch(tokenposition)//acessing the required element through the tokenposition counter
{
case 0://NAME
strcpy(emp[lineposition].name,token);
break;
case 1://ID
strcpy(emp[lineposition].id,token);
break;
case 2://PASSWORD
strcpy(emp[lineposition].password,token);
break;
case 3://CASUAL LEAVE
emp[lineposition].casual=atoi(token);
break;
case 4://MEDICAL LEAVE
emp[lineposition].medical=atoi(token);
break;
case 5://EARNED LEAVE
emp[lineposition].earned=atoi(token);
break;
}
token =strtok(NULL,",");
tokenposition++;//to access the next token in the same line
}
lineposition++;//after all the tokens are put in a structure,wwe move to the next line and redo the entire process of reading a line
}
}
int login()
{
int i;//for the loop
char userid[9];//user ID int he majn function,this will be passed to the the login function
char userpassword[5];//user password in the main function
printf("ENTER YOUR 8 CHARACTER USER ID\n");
scanf("%s",userid);
printf("ENTER THE 4 CHARACTER PASSWORD\n");
scanf("%s",userpassword);
linematched=0;
for(i=0;i<5;i++)
{
if((strcmp(emp[i].id,userid)==0)&&(strcmp(emp[i].password,userpassword)==0))//checking if login credentils are corre3ct or wrong
{
linematched=i;
printf("WELCOME %s TO THE LEAVE MANEGMENT SYSTEM\n",emp[linematched].name);
return 1;//TO INDICATE THAT USER WAS FOUND AND LOGIN WAS SUCCESFUL
break;
}
}
}
int deduction(int linematched,int days,int type_of_leave)//here all inputs are validated for the second time after the validation in main function
{
switch(type_of_leave)
{
case 1://casual leave
{
if(days>emp[linematched].casual)
{
printf("SORRY YOU HAVE EXHAUSTED YOUR LEAVE QUOTA\n\n");
again();
return 0;
break;
}
else
{
emp[linematched].casual=emp[linematched].casual-days;
return 1;
break;
}
break;
}
case 2://medical leave
{
if(days>emp[linematched].medical)
{
printf("SORRY YOU HAVE EXHAUSTED YOUR LEAVE QUOTA\n\n");
again();
return 0;
break;
}
else
{
emp[linematched].medical=emp[linematched].medical-days;
return 1;
break;
}
break;
}
case 3://earned leave
{
if(days>emp[linematched].earned)
{
printf("SORRY YOU HAVE EXHAUSTED YOUR LEAVE QUOTA\n\n");
again();
return 0;
break;
}
else
{
emp[linematched].earned=emp[linematched].earned-days;
return 1;
break;
}
break;
};
};
}
void quit()
{
char ans[5];
printf("ARE YOU SURE YOU WANT TO QUIT THE WIZARD? Y OR N\n");
scanf("%s", ans);
if (tolower(ans[0]) == 'y')
{
final_print();
printf("\n\n");
printf("---THANK YOU FOR USING OUR PORTAL--\n");
}
else
{
main2();
}
}
void again()
{
char ans1[5];
printf("SEARCH AGAIN USING ID AND PASSWORD? Y OR N\n");
scanf("%s", ans1);
if (tolower(ans1[0]) == 'y')
{
main2();//FOR RE-LOGIN PROCESS
}
else
{
quit();
}
printf("\n\n\n\n\n\n");
}
void final_print()
{
printf("----------------FINAL STATEMENT OF LEAVE OF EACH EMPLOYEE------------------------\n\n");
int i;
for (i = 0; i < 5; i++)
{
printf("NAME : %s\n",emp[i].name);
printf("USER ID : %s\n",emp[i].id);
printf("CASUAL LEAVE LEFT : %d\n",emp[i].casual);
printf("MEDICAL LEAVE LEFT : %d\n",emp[i].medical);
printf("EARNED LEAVE LEFT : %d\n\n",emp[i].earned);
}
printf("---------THANK YOU FOR USING LEAVE MANEGMENT PORTAL-----\n");
}
With
struct Empdetials
{
char name[25];
char id[9];//onr extra character to store /n
char password[5];
int casual;//casual,medical,earned leave as per the question
int medical;
int earned;
}emp[5];
you do basically two things in one step: (1) define struct Empdetials and (2) define a variable emp; Note that you cannot define a global variable in a headerfile, at least if you intend to include this header file in different .c-files.
You will need to separate the definition of struct Empdetials, the declaration of a global variable emp and the definition of this global variable in exactly one translation unit (i.e. exactly one .c-file). Note the extern-keyword in emp.h, which declares that emp will be defined once elsewhere (i.e. in emp.c later):
emp.h:
struct Empdetials
{
char name[25];
char id[9];//onr extra character to store /n
char password[5];
int casual;//casual,medical,earned leave as per the question
int medical;
int earned;
};
extern struct Empdetials emp[5]; // declaration of emp
emp.c:
#include "emp.h"
struct Empdetials emp[5]; // definition of emp
int main() { ...
again_final.c:
#include "emp.h"
// Note: no struct Empdetials emp[5]; any more...
again() { ...
login.c:
#include "emp.h"
// Note: no struct Empdetials emp[5]; any more...
login() { ...

C - segmentation fault when comparing integers

here is a part of my code. When I run my code, it's requesting an input from user and then matching it with another integer which recorded in my structure. When user input is matching, it is working correct. But when user enters a wrong input, it gives a segmentation fault. In where, I should make changes on my code?
long int userInput,endCheck; // Input from user
int flag=0; // check for match
int status;
int c; // controlling ctrl+D
int position= 999; // position of where the user input and data matched
LABEL:
printf("\n\t---------------------------------------\n");
printf("\n\nPlease enter the student ID which you want to find(3-times CTRL+D for finish):\n");
scanf("%d",&userInput);
if( (c=getchar()) == EOF){
exit(0);
}
for(i=0;i<lines,flag==0;i++){
if(index[i].id == userInput){
position=i;
flag=1;
}else{
position=999;
}
}
if(flag==0){
printf("id not found");
}
studentInfo info; // for storing the information which we will take between determined offsets
if(position!= 999){
if ( (pos = lseek(mainFile,index[position].offset , SEEK_SET)) == -1)/*going to determined offset and setting it as starting offset*/
{ perror("classlist"); return 4; }
while ( (ret= read(mainFile,&info, sizeof(info))) > 0 ){
printf("\n\nStudent ID: %d, Student Name: %s\n\n",info.id,info.name);
break;// to not take another students' informations.
}
}
flag=0;
goto LABEL;
printf("Program is terminated");
The right way to do that loop with the unwanted comma is like this. When you find the right index[i].id you can exit the loop early by using break.
for(i=0;i<lines;i++){
if(index[i].id == userInput){
position=i;
flag=1;
break;
}
}
You don't need the else branch as position is set to 999 from the outset of the code. But really you shouldn't use position in this fashion. What if you have more than 999 records? You're already using flag to identify if you've set position to a valid value. You should replace any instance of if(position!= 999) with if(flag).
Or since position is a signed int, you could use a negative value and ditch the flag.
The reason can be the fact that you are reaching an index that doesn't exist in the end of cycle, in the moment of the "if" statement with iterator "i".
Or in the last if, where you access a "position" index of the array. Check those limits.
Also, try GDB, is useful for solving this kind of problems.

Assignment to write a program that gives the user a choice between two options - C

I have an assignment due and I am drawing a blank on what exactly to do... I'm sure it is simple but I havent quite gotten the hang of things yet. The assignment is -
Write a program that gives the user 2 menu options: either call a function that will print a greeting and your name 4 times or call a function that will count down from 10 to 0 and then print "Blastoff!". Both functions should use for loops to print the appropriate output.
I have the prompt and the functions done so far... but I am unsure of how to display one or the other depending on the choice the user makes. Thank you for your help.
#include <stdio.h>
int main (void){
// declare counter variable
int i;
// prompt the user to make a choice
printf("What would you like to do?\n 1. Print my name\n 2. Count down from 10\n");
printf("\n");
// display greeting and name 4 times
for(i=1;i<=4;i++)
{
printf("Hi, my name is Bridget\n");
}
// display countdown
for(i=10;i>=0;--i)
{
printf("%d\n", i);
}
printf("Blastoff!");
}
You should read the input from user's keyboard:
int c;
c = getchar();
if (c == '1')
{
// display greeting and name 4 times
for(i=1;i<=4;i++)
{
printf("Hi, my name is Bridget\n");
}
}
if (c == '2')
{
// display countdown
for(i=10;i>=0;--i)
{
printf("%d\n", i);
}
}
printf("Blastoff!");
you should use Switch case.
switch(choice) {
case 1: //first for loop
break;
case 2: //second for loop
break;
}
Looks like you are missing a couple of points here. Firstly, you have not yet written any functions. Try looking here to gain some insight on that front.
Secondly, to make a choice based on user input you need to actually get that input somehow. You'll probably want to use scanf.
Lastly, once you have the user's input (say, in a variable declared as int input;) you can use if to control the flow of your program based on that variable like this:
if(input == 1){
greet();
}
else {
countDown();
}
Cheers! If you have any further questions feel free to comment below.
First of all you haven't actually declared you functions. Functions in C should be declared like the main function is. For more info in this see here.
// display greeting and name 4 times
void greeting(){
for(i=1;i<=4;i++)
{
printf("Hi, my name is Bridget\n");
}
}
void countdown() {
// display countdown
for(i=10;i>=0;--i)
{
printf("%d\n", i);
}
printf("Blastoff!");
}
To get the user's input the most common way is by keyboard. scanf accomplishes that in C. Details on scanf here
int main(void){
int i, choice;
//prompt the user to make a choice
// You don't need 2 printf for the newlines stick them to one.
printf("What would you like to do?\n 1. Print my name\n 2. Count down from 10\n\n");
//This takes the user's input and puts it in the variable choice
scanf(%d, &choice);
}
Lastly to decide what to do based on the user input you can use either an if then else statement or a switch. I will provide a solution with an if statement and you can figure the one with the switch on your own. Your final code should look like this.
int main(void){
int i, choice;
//prompt the user to make a choice
// You don't need 2 printf for the newlines stick them to one.
printf("What would you like to do?\n 1. Print my name\n 2. Count down from 10\n\n");
//This takes the user's input and puts it in the variable choice
scanf(%d, &choice);
if(choice == 1){
greeting();
}else{
countdown();
}
}
// display greeting and name 4 times
void greeting(){
for(i=1;i<=4;i++)
{
printf("Hi, my name is Bridget\n");
}
}
void countdown() {
// display countdown
for(i=10;i>=0;--i)
{
printf("%d\n", i);
}
printf("Blastoff!");
}
Bear in mind that this code has a lot of flaws (error checking mainly) but I guess your assigment is not about that.
First of all you need to include libraries with function you will need. You do this by
#include <someLibrary.h>
at the beggining of you document. Libraries mostly have .h extension. Always look for them if you try to do something. You consider them to have best performance and functionality as possible (not always true).
What is next you declare your functions. Function has name, arguments which are going into it, body in which they do something and return value (can be float, int, char etc). If function doesnt return anything, they return void (dont have return at the end). You declare functions before main() with only types of arguments. Whole body is after main (it is better looking).
If you declared function with arguments, you have to provide these arguments to function in () brackets. Even if no arguments are needed, you use them like getch() in example below. Note that function become what it return. If you declared some new variables in function they will be visible only in function. On the other hand function will not see any variable from other function (main too). If you want so, declare global variables (not recommended).
#include <stdio.h>
#include <conio.h> //libraries
void function1(int);
float function2(float); //declaration of functions
int main()
{
char decision;
printf("press 'a' to run function1, press 'b' to run function2\n");
decision=getch(); //first see getch()? look in google for functionality and library !
int someInt=10;
float someFloat=11;
if(decision== 'a')
{
function1(someInt);
}
else if(decision == 'b')
{
printf("%f", funcion2(someFloat)); //example that function become what they return
}
else
{
printf("No decision has been made");
}
getch(); //program will wait for any key press
return 0;
}
void function1(int param1)
{
//print your stuff // this function return void, so doesnt have return; statement
}
float function2(float param1)
{
return 2*param1; //this function have to return some float
}

Troubles appending structure to file in C

I'm having some trouble to append a structure to a file:
OS: Ubuntu 14.04
Struct:
struct baris
{
char name[30];
char trusted[1];
int phone;
int id;
};
Func:
addNewBariga()
{
char answer[30];
struct baris new;
while(1){
printf("Enter new Barigas' ID please.");
scanf("%d",&new.id);
printf("Enter new Barigas' name please.\n");
scanf("%s",new.name);
printf("Enter new Barigas phone please. \n");
scanf("%d", &new.phone);
printf("Is Bariga trusted?\n\t[Y/N]:");
scanf("%s",new.trusted);
while(1)
{
if(strcmp(new.trusted,"Y") != 0 && strcmp(new.trusted,"y") != 0)
{
printf("%s",new.trusted);
printf("\nWrong command givven.\t\n[Y/N]:");
scanf("%s",&new.trusted);
}
else
break;
}
printf("Values you've entered:\n\tID:%d\n\tName: %s\n\tPhone: %d\n\tTrustworth:%s\nWould you like to proceed to saving?\n[Y/N]:\n",new.id,new.name,new.phone,new.trusted);
scanf("%s",&answer);
if(strcmp(answer,"Y") ==0 || strcmp(answer,"y")==0) //Process to saving
{
printf("saving...");
confPtr = fopen(filePath , "ab");
//fwrite(new.id, sizeof(new.id), 1, confPtr);
fwrite(&new, sizeof(struct baris), 1, confPtr);
fclose(confPtr);
break;
}
}
What I'm getting:
fabio\00\00\00\00\00\00\00\00\00fab\00\00\00\00\00\00\00\00\00fab\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00 <1\B5y\00\00\00\00\00\00\00fab\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00 \C5f\DAy\00\00\00\00\00\00\00
That output looks basically correct, what did you expect?
You're writing binary data to a binary file. Binary files are not very easy to inspect manually.
The first member of the structure, name, will always be 30 bytes long in the output for example.
Note as pointed out by #BLUEPIXY in a comment that this:
scanf("%s",new.trusted);
triggers undefined behavior if a non-zero length is entered, since trusted is only 1 character long that is consumed by the string terminator. You should increase its length, or (much better!) stop using direct scanf() like this and instead read a whole line of input with fgets() and parse it using sscanf().
Also, when using functions that can fail (like scanf(), sscanf() or fgets()) you must check the return values before relying on them to have succeeded.

C programming opening and reading from a file

int main(void){
FILE *ifp; //input file pointer
int totalClock; //total clock count
// BEGIN OPERATIONS=============================
ifp=fopen("prog1.asy.txt", "r");
system("PAUSE");
assert(ifp!=NULL);
//populate the instMem with inst===================
int i=0;
//system("PAUSE");
for (i=0;i<512;i++)
{
inst temp=parser(ifp);
if (temp.opcode==-1)
break;
instMem[i]=temp;
printf("%s\n", instMem[i].rawCode);
}
printf("\n%d instructions parsed\n", i-1);
system("PAUSE");// PAUSE TO CHECK CODE PARSING IS CORRECT========
int cont=0;
while (cont==0){
//begin sim================================================
//initialize the mem=======================================
int i;
for (i=0;i<512;i++)
data[i]=0;
for (i=0;i<32;i++)
reg[i]=0;
IF_Time=0;
ID_Time=0;
EX_Time=0;
MEM_Time=0;
WB_Time=0;
//prompt input parameters===================================
printf("Memory access time: c=");
scanf("%d", &c);
printf("\nMultiply time: m=");
scanf("%d", &m);
printf("\nExecute time: n=");
scanf("%d", &n);
assert(c>0);
assert(m>0);
assert(n>0);
//start execution now that the program has been broken to unparsed strings====
while (0==0)
{
WB();
MEM();
if (MEM_WB.instruction.opcode==HALT)
break;
EX();
ID();
IF();
totalClock++;
system("PAUSE");
}
//PRINT RESULTS=============================================
printf("Run again with new parameters? 0=yes");
scanf("%d", &cont);
}
fclose(ifp);
system("PAUSE");
return 0;
}
struct inst parser(FILE *ifp){
char str[100];
struct inst temp;
if (fgets(str, 100, ifp)==NULL) {
inst temp={"NULL", -1,0,0,0};
}
else {
inst temp={str, 0,0,0,0};
puts(str);
}
return temp;
}
I am trying to read in a test file so that i can parse it into strings for analysis later. It opens the test file but it doesn't read the lines of test in the code. Is there something I am doing wrong.
Your parser functions only reads once from the file and does nothing with the result (since temp would be a local variable to the if branch, not to the function). First thing is to remove inst from inst temp = ... to see that it reads the first instruction. Then, you need to make that function loop over all lines in the file.
First of all, you need to format your source code on this page to make it more readable.
For parser(), I don't think you can return a structure. So please use a pointer instead. And, as Mihai mentions, "temp" is a temporary variable located on the stack, and it will be destroyed when returning from function parser().
I don't see the declarations of variables in the code snippet:
IF_Time=0;
ID_Time=0;
EX_Time=0;
MEM_Time=0;
WB_Time=0;
So I assume you could remove some unused code to make the question clear.
The last thing is: to analyze log files, shell scripts is more suitable than C. If you're not working on a UNIX/Linux box, you could also use Perl/Python if you want. They are all less error prone and easy to debug when used to analyze log files.

Resources