ahamed101 40 Junior Poster

Try this

dd="20130409"
date -d $dd -d "next monday" +%Y%m%d

--ahamed

ahamed101 40 Junior Poster

Hi All,
Let me explain the problem.

I have multiple include files as in class1.inc, class2.inc, class3.inc etc. Contents of an include file will be like

class1.inc

{
"john",
12,
68,

"steve",
12,
98,

"mat",
12,
95,

};

This will basically serve as a static array of structures. Here there are three field name(char*), age(int), avg(float).
In my program I want to assign the value of one of these file to a structure variable. My code goes like this

struct std_
{
	char name[50];
	int age;
	float avg;
}
std_str, *std_ptr;

int main(int argc, char **argv)
{
		
	if(!strcmp(argv[2],"class1")
	{
		static std_str obj[200] = 
		#include "class1.inc"
		
		...
	}
	else if(!strcmp(argv[2],"class2")
	{
		...	
	}
return 0;
}

The above code will work fine. But what I want is

int main(int argc, char **argv)
{
	char file[50];

	/* I want to dynamically generate the include file name and include it */
	strcat(file, argv[2]);
	strcat(file, ".inc")
		
	static std_str obj[200] = 
	#include file
	
return 0;
}

But unfortunately, the compilation fails, saying #include expects a file name.

Is there anyway to achieve this?

Thanks and Regards,
Ahamed.

ahamed101 40 Junior Poster

First thing first...
You want to calculate the age of a particular user, why do want an array for that?...

Second...

/* Function Prototype */
int calAge(int currentYear[],int currentMonth[],int currentDay[],int birthYear[],int birthMonth[],int birthDay[])
/* Function Call */				calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);

The above function call and prototype does not match... In the function prototype, you have declared arrays as arguments... but in the function call you are not passing the arrays instead just a particular value(of an array)... this will surely make your program crash...

If all you want is to calculate the age of the person, just do it like this...

/* Function Prototype */
int calAge(int currentYear,int currentMonth,int currentDay,int birthYear,int birthMonth,int birthDay){
/* Put in your logic(existing one) without any array stuff */
}
/* Function Call */				calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);

Next...

/* Not a good idea */
void main()
/* Use this instead */
int main(int argc, char **argv)

Next...

/* This is wrong... */
scanf("%s",&name[i]);
/* You are taking in a string(array of chars), so no need of &, use it this way */
scanf("%s",name[i]);
Aia commented: That's a lot of effort; going through that code. +10
ahamed101 40 Junior Poster

You can read and write simultaneously like Sci@phy suggested...

1. Open file 1 in read mode
2. Open file 2 in append mode
3. read from file 1
4. do the processing
5. write to file 2
6. continue from step 3 till end of file of file 1
7. close file 2
8. close file 1

ahamed101 40 Junior Poster

Hi All,

newt.c_cc[VMIN] = 1;
newt.c_cc[VTIME] = 0;

need to set this... it worked and thanks a lot to frk who helped me in this...

Salem commented: Well done, and thanks for the update for the solution. +22